C# winform编程中,如何才能在在鼠标移过checkedListBox控件里的item的时候 得到item的值?并且这时弹出一个tooltip将值显示到tootip上面呢?

解决方案 »

  1.   

    这个很有难度,鼠标移过的事件有,checkedListBox的坐标也能弄到,关键是怎么知道Item的坐标,还要显示tooltip
      

  2.   

    除非重写一个checkedListBox,不然很难实现.
    可换一个思路,把value和text的值组合起来显示在界面上:
    select value,(value+text)as text from table1
      

  3.   

    自定义一个控件,代码如下:
    public partial class XListBox : ListBox
        {
            int rowHeight;  //行高
            public XListBox()
            {
                InitializeComponent();            rowHeight = this.Font.Height;
            }        protected override void OnPaint(PaintEventArgs pe)
            {
                // TODO: 在此处添加自定义绘制代码            // 调用基类 OnPaint
                base.OnPaint(pe);
            }        private void XListBox_MouseMove(object sender, MouseEventArgs e)
            {
                int rowIndex = e.Y / rowHeight;
                if (rowIndex < this.Items.Count)
                {
                    this.SelectedIndex = (e.Y / rowHeight);
                } 
            }
        }在调用这个控件的SelectedIndexChanged事件里面你可以获得选中item的值,然后弹出tooltip等
      

  4.   

    添加如下的代码试试看:
    private void checkedListBox1_MouseMove(object sender, MouseEventArgs e)
    {
    int index = this.checkedListBox1.IndexFromPoint(e.X, e.Y);
    if (index != -1)
    {
    string text = this.checkedListBox1.Items[index].ToString(); this.toolTip1.SetToolTip(this.checkedListBox1, text);
    }
    }
      

  5.   

    呵呵,看错问题了,hbxtlhx 正解