how to use a custom cursor (.cur)

I have made a .cur file and have embeded it in my.resources so I can easily acess it from in my code but I don't know the correct syntax. Whatever I try never works. Can someone please tell me the few lines of code I need to use my cursor?
[240 byte] By [CrazyEngineerKid] at [2007-12-22]
# 1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim Cur As Cursor = New Cursor("c:\windows\cursors\pen_rm.cur")

Me.Cursor = Cur

End Sub

TallDude at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2

Thanks for the help! I will definantly try this code. Although I am Guessing I should change the

("c:\windows\cursors\pen_rm.cur") to

(my.resources.MyCursor.cur) because it is embedded.

CrazyEngineerKid at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 3

I tried it and this error message came up. It is probely something basic, but is there possibly anything left out in the line:

Dim Cur As Cursor = New Cursor("c:\windows\cursors\pen_rm.cur")

Thanks for trying!

Error 1 Overload resolution failed because no accessible 'New' can be called with these arguments:
'Public Sub New(stream As System.IO.Stream)': Value of type '1-dimensional array of Byte' cannot be converted to 'System.IO.Stream'.
'Public Sub New(fileName As String)': Value of type '1-dimensional array of Byte' cannot be converted to 'String'.
'Public Sub New(handle As System.IntPtr)': Value of type '1-dimensional array of Byte' cannot be converted to 'System.IntPtr'. C:\Documents and Settings\Brian\My Documents\Visual Studio 2005\Projects\Target Practice\Target Practice\Form1.vb 575 29 Target Practice

CrazyEngineerKid at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 4

I'm sorry. I posted code to load a cursor from a file, not an embedded resource.

The only 'hack' I can figure out to use, to load the cursor as an embedded file, is to create it as an icon. (and then do some jumping through hoops!)

I think currently cursors can only be black and white and transparent color and 32x32.

Anyway, to load an icon (from a file, but it will become an embedded cursor,) is as follows:

(Experts. Please help on this and tell him the right way to do this!)

Public Class Form1

' add an empty 'form2' to your project to reset form1's icon from.

' In the form1 designer, make the cursor 'ico' file,

' the icon for form1. Then ...

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim curr As New Cursor(Me.Icon.Handle)

Me.Cursor = curr

Me.Icon = My.Forms.Form2.Icon

End Sub

End Class

TallDude at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 5

Try:

Dim m As New System.IO.MemoryStream(My.Resources.MyWackyCursor)
Me.Cursor = New Cursor(m)

Unfortunately, cursors like this are only B&W (Tall dude mentioned that). You can create color ones (if you want) using the LoadCursorFromFile Win32 API, but that requires an actual file.

SJWhiteley at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 6

Thanks for the code SJWhiteley, it worked!

Dim m As New System.IO.MemoryStream(My.Resources.crosshaircur)

Me.Cursor = New Cursor(m)

This is the exact code I used.

CrazyEngineerKid at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 7

Stephen,

Thanks for showing us the correct way to do this.

BTW, when I used my 'hack' way, the cursor/pointer did not persist through

the lifetime of the application.

Can you explain why? Just curious.

TallDude at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...