WinForms cursor is hidden in only one form

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

+2
source share
5 answers

You can make the cursor empty and set myForm.Cursor = blankCursor; This will cause the particular form to display a specific cursor, which can be completely transparent.

+1
source

You need to implement this logic using the MouseEnter and MouseLeave events, each of which takes the form:

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

make abobe in the form that should hide the cursor and add it to the form that should make the cursor visible:

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

Have you this.Cursor = Cursors.None instead of Cursor.Hide() ?

0
source

You can use the Control.MouseEnter and Control.MouseLeave events to cause the cursor to be hidden or displayed

0
source

If you hide the cursor so that the user cannot do anything on the form, use this.UseWaitCursor = true; .

0
source

Source: https://habr.com/ru/post/923294/


All Articles