我想给我的WinForm的CheckedListBox添加右键,现在有个问题解决不了
无法取到鼠标当前项(也就是我要在那一项上激发鼠标事件),因为我的事件需要用到当前项的值做参数。
哪位高手可以指导指导呀?

解决方案 »

  1.   

    vb.net的:
        Private Sub ListBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseMove
            Dim intIndex As Integer
            intIndex = Int(e.Y / ListBox1.ItemHeight)
            If intIndex > ListBox1.Items.Count - 1 Then intIndex = ListBox1.Items.Count - 1
            Me.Text = ListBox1.Items(intIndex)
        End Sub没时间转c#的了,lz自己转一下吧
      

  2.   

    c#的:
            private void listBox1_MouseMove(object sender, MouseEventArgs e)
            {
                int intIndex;
                intIndex = e.Y / this.listBox1.ItemHeight;
                this.Text = intIndex.ToString();  //这里就是当前鼠标在listbox上的第几项位置,只要放在全局变量就可以在mousedown那调用了
            }
      

  3.   

    上面那里补充一下:
                if (intIndex>listBox1.Items.Count-1 )
                { 
                    intIndex=listBox1.Items.Count-1;
                }
      

  4.   

    兄弟,WinForm的CheckedListBox没有ItemHeight属性呀,ListBox是有的