I’m building a Windows Forms application in Visual Studio 2019 and I want to use the new hand cursor icon (red box) that is the default in Windows 10 when my cursor hovers over a button. However, Visual Studio 2019 is using the old hand cursor icon (orange box).
How can I change this so that Visual Studio 2019 uses the new hand cursor icon in my project?
3 Answers
Introduction
Visual Studio 2019 is a popular Integrated Development Environment (IDE) that is widely used for developing Windows applications. It provides a wide range of features and tools that make it easier for developers to create high-quality applications. One of the features that developers often use is the hand cursor icon. This icon is used to indicate that a button or control can be clicked or interacted with. In this blog post, we will discuss how to use the hand cursor icon in Visual Studio 2019.
What is the Hand Cursor Icon?
The hand cursor icon is a small icon that appears when the mouse is hovering over a clickable area in a Windows application. It is used to indicate that the area can be clicked or interacted with. The hand cursor icon has been a part of Windows for many years and has undergone several changes over time. In Windows 10, the hand cursor icon has been updated to a new design that is more modern and visually appealing.
How to Use the Hand Cursor Icon in Visual Studio 2019
By default, Visual Studio 2019 uses the old hand cursor icon (orange box) when the mouse is hovering over a button or control. However, it is possible to change this so that Visual Studio 2019 uses the new hand cursor icon (red box) that is the default in Windows 10.
To use the new hand cursor icon in Visual Studio 2019, follow these steps:
1. Open your Windows Forms application in Visual Studio 2019.
2. Select the button or control that you want to apply the new hand cursor icon to.
3. In the Properties window, scroll down to the Cursor property.
4. Click on the drop-down arrow next to the Cursor property to see the list of available cursors.
5. Select the Hand cursor from the list.
Once you have selected the Hand cursor, Visual Studio 2019 will use the new hand cursor icon (red box) when the mouse is hovering over the button or control.
Customizing the Hand Cursor Icon
In addition to using the default hand cursor icon, it is also possible to customize the hand cursor icon in Visual Studio 2019. This can be useful if you want to create a unique look and feel for your application.
To customize the hand cursor icon in Visual Studio 2019, follow these steps:
1. Open your Windows Forms application in Visual Studio 2019.
2. Select the button or control that you want to apply the custom hand cursor icon to.
3. In the Properties window, scroll down to the Cursor property.
4. Click on the drop-down arrow next to the Cursor property to see the list of available cursors.
5. Select the Custom cursor from the list.
6. Click on the ellipsis button next to the Custom cursor property to open the Cursor Editor.
7. In the Cursor Editor, you can create a custom cursor by drawing on the canvas or importing an image.
8. Once you have created your custom cursor, click on the OK button to close the Cursor Editor.
9. Visual Studio 2019 will now use your custom hand cursor icon when the mouse is hovering over the button or control.
Using the Hand Cursor Icon in Code
In addition to using the hand cursor icon in the Properties window, it is also possible to use it in code. This can be useful if you want to change the cursor dynamically based on user interaction or other events.
To use the hand cursor icon in code, follow these steps:
1. Open your Windows Forms application in Visual Studio 2019.
2. Select the button or control that you want to apply the hand cursor icon to.
3. In the Properties window, scroll down to the Cursor property.
4. Select the Default cursor from the list.
5. In the code for your application, add the following line of code to change the cursor to the hand cursor icon:
csharp
this.Cursor = Cursors.Hand;
6. When the code is executed, the cursor will change to the hand cursor icon.
Conclusion
The hand cursor icon is an important part of Windows applications and is used to indicate clickable areas to users. In Visual Studio 2019, it is easy to use the hand cursor icon in your Windows Forms application. By following the steps outlined in this blog post, you can use the default hand cursor icon or customize it to create a unique look and feel for your application. Additionally, you can use the hand cursor icon in code to change the cursor dynamically based on user interaction or other events.
To use the new hand cursor icon in your Windows Forms application in Visual Studio 2019, you can use the following steps:
- In the designer view of your form, select the button control that you want to change the cursor for.
- In the Properties window, locate the “Cursor” property.
- Click the dropdown arrow for the “Cursor” property and select “Hand”.
This should change the cursor for the button to the new hand cursor icon when the cursor hovers over the button.
Alternatively, you can also set the cursor for the button programmatically by using the following code:
button1.Cursor = Cursors.Hand;
This will set the cursor for the button to the hand cursor when the cursor hovers over the button.
In conclusion, to use the new hand cursor icon in a Windows Forms application in Visual Studio 2019, you can either set the “Cursor” property of the control to “Hand” in the Properties window, or you can set it programmatically using the Cursor property and the Hand constant of the Cursors class.
I hope this information was helpful! Let me know if you have any other questions.
I have found a solution to use the desired hand cursor icon in my Windows Forms application built with Visual Studio 2019, although it is not the most elegant solution. The standard cursors set in Windows.Forms includes a pre-defined hand cursor icon, rather than the one that the user has selected in their settings. It is possible that this is for compatibility with older versions of Windows that did not have this setting, but in any case, it seems that it is not possible to use the user-selected hand cursor icon.
To use the desired hand cursor icon, I found that the best option is to read the actual setting from Windows, locate the path to the cursor file, and use it to create a new cursor.
The path to the cursor file can be obtained through the registry using the following code: Registry.GetValue(@"HKEY_CURRENT_USER\Control Panel\Cursors", "Hand", null).ToString();
.
Although the Cursor
class does have a constructor that accepts the path to a cursor file, it is poorly implemented and can only handle black and white cursors, not animated cursors. To work around this, I used the following code, which utilizes the LoadCursorFromFile
method to load the cursor and the Cursor
class’ ownHandle
field to properly release the handle:
public static Cursor LoadCustomCursor(string path)
{
IntPtr hCurs = LoadCursorFromFile(path);
if (hCurs == IntPtr.Zero) throw new Win32Exception();
var curs = new Cursor(hCurs);
// Note: force the cursor to own the handle so it gets released properly
var fi = typeof(Cursor).GetField("ownHandle", BindingFlags.NonPublic | BindingFlags.Instance);
fi.SetValue(curs, true);
return curs;
}
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr LoadCursorFromFile(string path);
To use the custom cursor, call the LoadCustomCursor
method with the path to the cursor file obtained from the registry and set the Cursor
property of the desired control to the returned value. For example:
string path = Registry.GetValue(@"HKEY_CURRENT_USER\Control Panel\Cursors", "Hand", null).ToString();
var hand = LoadCustomCursor(path);
button1.Cursor = hand;
This solution has worked for both static and animated cursors on my system, but it is important to include error handling in case the cursor file is not found or there are other issues.
Note: The code in the provided examples is written in C#, which is a programming language developed by Microsoft for the .NET framework. It is used to create a variety of applications, including web, mobile, desktop, and console applications. C# is a statically-typed, object-oriented language that is designed to be simple, powerful, and easy to learn. It is commonly used in the development of Windows applications, particularly those using the Windows Forms or WPF (Windows Presentation Foundation) frameworks.