c# 判断listbox鼠标hover的item
答案:2 悬赏:0 手机版
解决时间 2021-02-21 15:57
- 提问者网友:不要迷恋哥
- 2021-02-20 17:45
c# 判断listbox鼠标hover的item
最佳答案
- 五星知识达人网友:轻雾山林
- 2021-02-20 18:11
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
Brush myBrush = Brushes.Black; //初始化字体颜色=黑色
this.listBox1.ItemHeight = 40; //设置项高,根据具体需要设置值
//为每个项设置字体颜色
//如果不需要可以不写此switch
switch (e.Index)
{
case 0:
myBrush = Brushes.Red;
break;
case 1:
myBrush = Brushes.Orange;
break;
case 2:
myBrush = Brushes.Purple;
break;
case 4:
myBrush = Brushes.White;
break;
}
e.Graphics.DrawString(listBox1.Items[e.Index ].ToString(), e.Font, myBrush, e.Bounds, null);
//这句好象可以不要,自己试下
e.DrawFocusRectangle();
}
{
e.DrawBackground();
Brush myBrush = Brushes.Black; //初始化字体颜色=黑色
this.listBox1.ItemHeight = 40; //设置项高,根据具体需要设置值
//为每个项设置字体颜色
//如果不需要可以不写此switch
switch (e.Index)
{
case 0:
myBrush = Brushes.Red;
break;
case 1:
myBrush = Brushes.Orange;
break;
case 2:
myBrush = Brushes.Purple;
break;
case 4:
myBrush = Brushes.White;
break;
}
e.Graphics.DrawString(listBox1.Items[e.Index ].ToString(), e.Font, myBrush, e.Bounds, null);
//这句好象可以不要,自己试下
e.DrawFocusRectangle();
}
全部回答
- 1楼网友:琴狂剑也妄
- 2021-02-20 19:47
private void listView1_MouseMove(object sender, MouseEventArgs e)
{
ListViewItem item = listView1.GetItemAt(e.X, e.Y);
if (item != null)
textBox1.Text = item.Text;
}
MouseMove比hover好些。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯