Is it possible to made a TCombo edit caret 'wi

2019-07-17 16:47发布

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条回答
做自己的国王
2楼-- · 2019-07-17 17:03

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;
查看更多
登录 后发表回答