在C#中提示的使用.NET 4.0 [英] usage of tooltip in C#.net 4.0

查看:190
本文介绍了在C#中提示的使用.NET 4.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是是否有可能从数据库中获取一些值显示为提示,在的ListBox特定值



情景:



我在的ListBox <几个项目/ code>,说,例如红色,黄色,白色。



当我选择/把我的鼠标箭头/聚焦接近该项目中的任何一个,在提示必须display..for例如,如果红色,那么提示应显示原色,如果黄,然后提示应显示辅助色。



我已经存储了原色,辅助色 ..,在提示聚焦时,在数据库中必须显示。



我的问题是,是否是它可以从数据库中获取一些值显示为提示,在列表框中特定值


解决方案

您可以通过挂钩这种方法您的列表框



<$ p的鼠标移动事件做到这一点$ p> 使用System.Windows.Forms的;

私人无效的OnMouseMove(对象发件人,MouseEventArgs E)
{
如果(发件人列表框)
{
列表框列表框=(列表框)发送;
点积分=新的点(e.X,e.Y);
INT hoverIndex = listBox.IndexFromPoint(点);
如果(hoverIndex> = 0&放大器;&安培; hoverIndex< listBox.Items.Count)
{
工具提示TT =新工具提示();
tt.SetToolTip(列表框,GetYourCustomTooltiphere);
}
}
}


My question is whether is it possible to fetch some values from database to show as a tooltip, for particular values in listBox?

Scenario:

I have few items in listBox,say for example red, yellow, white.

When i select / bring my mouse arrow / focused near any one of the item , the tooltip must display..for example, if red, then tooltip should display "primary color", if "yellow" ,then tooltip should display "secondary color".

I had stored the "primary color","secondary color",.. , the tooltip that must be showed when focused, in the database.

My question is whether is it possible to fetch some values from database to show as a tooltip, for particular values in listbox?

解决方案

You can do this by hooking this method to mouse move event of your listbox

using System.Windows.Forms;

private void onMouseMove(object sender, MouseEventArgs e)
{
   if(sender is ListBox)
   {  
      ListBox listBox = (ListBox)sender;
      Point point = new Point(e.X, e.Y);
      int hoverIndex = listBox.IndexFromPoint(point);
      if(hoverIndex >= 0 && hoverIndex < listBox.Items.Count)
      {
         ToolTip tt = new ToolTip();
         tt.SetToolTip(listBox, "GetYourCustomTooltiphere");
      } 
   }    
}

这篇关于在C#中提示的使用.NET 4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆