Setting a custom cursor from a resource file

In my VB.net project, I created a custom cursor (Window.cur). How to assign this to the cursor without using the full path to the file?

VB.Net has My.Resources, but it does not show the cursors embedded in the project.

I found an example that used this code: New cursor (Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream ("Window.cur"), but this does not work.

+6
cursor
source share
5 answers

Guessing the name of a resource can be difficult. To find out, run Ildasm.exe in your program. Double-click the Manifest and find .mresource.

Another way to do this is to avoid guessing: Project + Properties, Resource tab. Click the arrow on the "Add resource", "Add an existing file" button and select the .cur file. Make your code like this:

Dim ms As New System.IO.MemoryStream(My.Resources.Cursor1) Button1.Cursor = New Cursor(ms) 
+8
source share

Thanks for the help! I assumed that if I create a resource in the Visual Studio IDE, it will add it to my project. I was a fool!

I needed to go to the “Project” tab to add the Window.Cur file using “Add Resource” (thanks nobugz!), And then use the code that he mentioned:

 Dim ms As New System.IO.MemoryStream(My.Resources.Window) Button.Cursor = New Cursor(ms) 

I would vote for the answer if I could, but I can’t, because currently I have only 13.

+1
source share

You are missing a namespace. You probably want to use:

 MyNamespace.MySubfolder.Window.cur 

EDIT: Also, make sure that for your item "Action" for the item is "Embedded resource", otherwise it will not be included in your dll / exe.

0
source share

Suppose you assign "Cursor1.cur" to the cursor for the "Button1."

In your Form.Load event, you would do something like:

 Button1.Cursor = New Cursor(Me.GetType(), "Cursor1.cur") 
0
source share

you should not use 32-bit color cursors.

0
source share

All Articles