Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Custom Cursor from Resource File

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.

like image 809
KerryF Avatar asked Jan 11 '09 04:01

KerryF


2 Answers

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)
like image 135
Hans Passant Avatar answered Oct 18 '22 14:10

Hans Passant


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)
like image 20
KerryF Avatar answered Oct 18 '22 14:10

KerryF