Is it possible to made a TCombo edit caret 'wider' or to 'bold' it?

倾然丶 夕夏残阳落幕 提交于 2019-12-13 16:06:26

问题


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;


来源:https://stackoverflow.com/questions/12422720/is-it-possible-to-made-a-tcombo-edit-caret-wider-or-to-bold-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!