WinForms cursor hidden only on one Form

前端 未结 5 585
渐次进展
渐次进展 2021-01-21 02:40

I have a C# application with 2 simultaneous visible forms, and I need to hide mouse cursor when it is over only on one of them. If I use Cursor.Hide() it applies the change for

5条回答
  •  广开言路
    2021-01-21 03:28

    You need to implement this logic by using the MouseEnter and MouseLeave events one each form something like:

        private void frm1_MouseEnter(object sender, EventArgs e)
        {
           Cursor.Hide();
        }
        private void frm1_MouseLeave(object sender, EventArgs e)
        {
           Cursor.Show();
        }
    

    do the abobe on the form that should hide the cursor and add this to the form that should make the cursor visible:

        private void frm2_MouseEnter(object sender, EventArgs e)
        {
           Cursor.Show();
        }
    

提交回复
热议问题