In my VB.net project I created a custom cursor (Window.cur). How can I assign that to the cursor without having to use the full file path to that file?
VB.Net has My.Resources but it does not show the cursors that are embedded in the project.
I found an example that used code like this:
New Cursor(Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream("Window.cur")
but that does not work.
Guessing the resource name can be difficult. To find out, run Ildasm.exe on your program. Double-click "Manifest" and look for the .mresource.
Another way to do it that avoids guessing: Project + Properties, Resource tab. Click the arrow on the "Add Resource" button, Add Existing File and select your .cur file. Make your code look like this:
Dim ms As New System.IO.MemoryStream(My.Resources.Cursor1)
Button1.Cursor = New Cursor(ms)
Thanks for the help! I assumed that if I created the resource in the Visual Studio IDE it would add it to my project. Silly me!
I had to go to the Project tab to add the Window.Cur file using Add Resource (thanks nobugz!) and then use the code he mentioned:
Dim ms As New System.IO.MemoryStream(My.Resources.Window)
Button.Cursor = New Cursor(ms)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With