private void listBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(鼠标指针不在当前选中行上) 鼠标指针移动到选中行;
        }

解决方案 »

  1.   

            private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                Point pt = new Point();
                pt.X = listBox1.Width / 2;
                pt.Y = listBox1.SelectedIndex * listBox1.ItemHeight + listBox1.ItemHeight / 2;
                Cursor.Position = listBox1.PointToScreen(pt);
            }
      

  2.   


    private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (listBox1.SelectedIndex != -1)
                {
                    Rectangle rt = listBox1.GetItemRectangle(listBox1.SelectedIndex);
                    Cursor.Position = listBox1.PointToScreen(rt.Location);
                }
            }