C# Winform mouse cursor style setting method

Lionsure 2020-07-16 Original by the website

The default mouse cursor style is a white arrow in Winform, and it does not change to a finger shape when moved to the button. It is not easy to distinguish whether it can be clicked(especially when the button style is not the default). If the mouse cursor is moved over the button, it will automatically change into a finger shape, like a link in a web page, it is easy to distinguish whether it can be clicked, regardless of whether the button style is completely changed (for example: the style is set to Flat or Popup, and the background color is replaced by the background image).

There are two methods for setting mouse cursor style in C# Winform, one: set in the control properties; the second: set with code. The following are the specific setting steps and implementation codes of these two methods.

 

I. Set mouse cursor style with properties in C# Winform

1. Select the button, move the mouse to the "Properties" window on the right to expand it(Or right-click the button, select "Properties" in the pop-up menu, or select "View → Properties Window"), as shown in Figure 1:

Set mouse cursor style with properties in C# Winform

Figure 1

2. Click the drop-down list box to the right of the Cursor property, drag the slider on the right to the bottom, and select Hand.

3. After saving and regenerating, move the mouse to the button to see if it has automatically changed into a finger shape.

 

 

II. Set mouse cursor style with code in C# Winform

1. Select the button, expand the "Properties" window on the right, and select the Event icon, as shown in Figure 2:

Set mouse cursor style with code in C# Winform

Figure 2

2. Add button1_MouseMove to the right of MouseMove, click anywhere to open the background code window, and add the following code to the button1_MouseMove event:

private void button1_MouseMove(object sender, MouseEventArgs e)
       {
              Cursor.Current = Cursors.Hand;//Set the mouse to finger shape
       }