[英]How can I show hints for droppeddown TComboBox items in Delphi 10.3.3?
我必须显示下拉TComboBox
项目的提示。
为此,我可以使用OnMouseMove
事件来处理悬停消息。 它将鼠标 X,Y 客户端坐标作为参数。 如果我可以确定要绘制的第一个项目(带有垂直滚动条的下拉列表),那么我可以使用ItemHeight
值确定 cursor 下的项目。
是否有任何 Win32 API 调用消息来获取此值? IDE 不支持此信息,或者我找不到。
一种选择是使用 cxOwnerDrawXXXX 样式 ComboBox 和 OnDrawItem 事件,它会告诉您何时绘制焦点项目。 我自己曾经使用过这种方法来更新文本框中的 static 提示,该提示提供有关焦点/悬停在项目上的更多信息。
将提示文本放入 StaticText 控件的示例:
procedure TForm1.ComboBox1CloseUp(Sender: TObject);
begin
StaticText1.Caption := '';
end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect:
TRect; State: TOwnerDrawState);
begin
// Update a hint on a static control
if (odSelected in State) and (Control as TComboBox).DroppedDown then
StaticText1.Caption := 'Hint for value:' + (Control as TComboBox).Items[Index];
// Draw list item
with (Control as TComboBox).Canvas do
begin
FillRect(Rect);
TextOut(Rect.Left, Rect.Top, (Control as TComboBox).Items[Index]);
end;
end;
可以适应激活/显示/存储提示,而不是更新 static 控件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.