c# 判断listbox鼠标hover的item 5
2个回答
展开全部
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();
}
展开全部
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好些。
{
ListViewItem item = listView1.GetItemAt(e.X, e.Y);
if (item != null)
textBox1.Text = item.Text;
}
MouseMove比hover好些。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询