用户鼠标停在ComboBox的哪一项上?
窗口上有个ComboBox。用户点击向下箭头,弹出一个列表框。用户鼠标在列表框上移动。
要求另一个标签实时显示用户鼠标停在哪一项上。
注意,用户从来没有选择一项!就像你鼠标滑过超链接,只见文字加了下划线,而你从没有点击它们一样。
[解决办法]
自己添加鼠标效果protected override void WndProc(ref Message m)
{
if (m.Msg == 0x020A)
{}
else
{
base.WndProc(ref m);
}
}
http://www.codeproject.com/KB/combobox/ComboBoxFiringEvents.aspx
[解决办法]
this.comboBox1.DrawMode = DrawMode.OwnerDrawFixed; this.comboBox1.DrawItem += new DrawItemEventHandler(comboBox1_DrawItem); } void comboBox1_DrawItem(object sender, DrawItemEventArgs e) { string txt = this.comboBox1.Items[e.Index].ToString(); Graphics g = e.Graphics; Font f = new Font("宋体", 9); if (e.State == DrawItemState.Selected) { this.label2.Text = txt; g.FillRectangle(Brushes.Blue, 0, e.Index * 15, this.comboBox1.Width, 12); g.DrawString(txt, f, Brushes.White, 0, e.Index * 15); } else { g.FillRectangle(Brushes.White, 0, e.Index * 15, this.comboBox1.Width, 12); g.DrawString(txt, f, Brushes.Black, 0, e.Index * 15); } }