TComboBox当鼠标在下拉列表上移动(并未选定)时能触发什么事件吗
编号:QA003727
建立日期: 2001年1月1日 最后修改日期:2001年1月1日
所属类别:
jchc:
操作系统: win9x,winnt 4.0
编程工具: delphi 5
问题: TComboBox当鼠标在下拉列表上移动(并未选定)时能触发什么事件吗?因为我想得到当前鼠标正在哪个Item上。
水平: 中级
回答:
自定义ComboBox.OnDrawItem事件,设置ComboBox.Style为csOwnerDrawFixed。在OnDrawItem事件中,添
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
if odSelected in State then
begin
ComboBox1.Canvas.Brush.Color:=clHighlight;
ComboBox1.Canvas.Font.Color:=clHighlightText;
Caption:=ComboBox1.Items[index];
end
else
begin
ComboBox1.Canvas.Brush.Color:=clWindow;
ComboBox1.Canvas.Font.Color:=clWindowText;
end;
ComboBox1.Canvas.TextRect(rect,rect.left+2,rect.top+2,ComboBox1.Items[index]);
end;
则Form1的Caption会显示当前鼠标所在Item。
此问题由ylzh回答。
| |
|
|
| |
|
|