Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I feel like a dunce having to ask this, but I have spent more than 1 Hour in MS Documentation, and can't find a reasonable example of how to set the default cursor for a windows form in a VS2019, VB,net desktop application.

I have a form that has the Cursor property set to Wait cursor. When I try to change the property to an arrow, it goes back to a wait cursor. Not sure what is going on with that.
Other forms I add default to the arrow cursor.

What I have tried:

I have spent more than 1 Hour in MS Documentation
Posted
Updated 16-Mar-22 9:12am
v2

With the Designer you can select any of the standard cursors (members of Cursors class) as the default cursor of the Form/Control you are designing.

If none of the standard cursors are to your liking, you can assign a custom Cursor to the Form/Control's Cursor property; this takes your explicit code, e.g. in the Form constructor or the Load handler.

Custom Cursors can be created in many ways; I tend to store them as a resource within the EXE file and load them from there, using code like this (warning: C#):
C#
// to make a cursor (.CUR) file:
// create a 32-bit image and store it as PNG (this allows transparent color)
// use a transparant border if full 32*32 cursor would be too large
// use on-line converter https://www.filezigzag.com/online-png-to-cur-converter
public static Cursor GetEmbeddedCursor(string filename) {
    string resourceName = "?";
    try {
        resourceName = "myNameSpace.Resources." + filename;
        Assembly assembly = Assembly.GetEntryAssembly();
        using (Stream myStream = assembly.GetManifestResourceStream(resourceName)) {
            return new Cursor(myStream);
        }
    } catch (Exception exc) {
        log("Exception in GetEmbeddedCursor: " + filename + ", " + resourceName);
        log(exc);
        return null;
    }
}
 
Share this answer
 
Comments
Slow Eddie 16-Mar-22 15:34pm    
I am sorry I was not explicit enough. I don't need a custom cursor, just the default cursor.
Luc Pattyn 16-Mar-22 15:43pm    
Simple:
Cursor=Cursors.Default
 
Share this answer
 
v3
Comments
Slow Eddie 16-Mar-22 15:31pm    
This worked, sort of. I get the default cursor like I want but for several seconds it shows both the arrow cursor and the wait cursor. Thanks, this has me on the right track.
RickZeeland 16-Mar-22 15:34pm    
Maybe you have also set a cursor property somewhere for a control in the designer?
Slow Eddie 16-Mar-22 15:34pm    
Also, I failed to mention that the form in question is set as the startup form. I don't know if this has any relevance or not.
RickZeeland 16-Mar-22 15:41pm    
Don't think so, but I can only speak from a C# background.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900