I have an mode that uses TComboBox.SelStart
to indicate progress along the edit text string. In this mode I would like to make some kind of change to the edit caret, for example to widen it to 2 pixels or 'bold' it in some way to indicate this mode and to have it grab more attention. Is this possible?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Yes, as Alex mentioned in his comment, this can be done using API calls. Example:
procedure SetComboCaretWidth(ComboBox: TComboBox; Multiplier: Integer);
var
EditWnd: HWND;
EditRect: TRect;
begin
ComboBox.SetFocus;
ComboBox.SelStart := -1;
Assert(ComboBox.Style = csDropDown);
EditWnd := GetWindow(ComboBox.Handle, GW_CHILD);
SendMessage(EditWnd, EM_GETRECT, 0, LPARAM(@EditRect));
CreateCaret(EditWnd, 0,
GetSystemMetrics(SM_CXBORDER) * Multiplier, EditRect.Height);
ShowCaret(EditWnd);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SetComboCaretWidth(ComboBox1, 4); // bold caret
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SetComboCaretWidth(ComboBox1, 1); // default caret
end;