本文介绍了是否可以将TCombo编辑插入记号“变大”或“变粗”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用 TComboBox.SelStart
的模式来指示编辑文本字符串的进度。在这种模式下,我想对编辑插入符号进行某种更改,例如将其加宽到2像素或以某种方式加粗以指示此模式并引起更多关注。
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?
推荐答案
是的,正如Alex在其评论中提到的那样,可以使用API调用来完成。示例:
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;
这篇关于是否可以将TCombo编辑插入记号“变大”或“变粗”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!