.cur from resource file / memory stream
i'm trying to add custom mouse icons to my app.
but i can't seem to do it.
currently, everything i find on the internet says this code works:
Code:
Dim ms As New System.IO.MemoryStream(My.Resources.MouseCursor)
Me.Cursor = New Cursor(ms)
but it gives me an error:
WITH PNG: (compile error)
Code:
Error 2 Overload resolution failed because no accessible 'New' can be called with these arguments:
'Public Sub New(buffer() As Byte)': Value of type 'System.Drawing.Bitmap' cannot be converted to '1-dimensional array of Byte'.
'Public Sub New(capacity As Integer)': Value of type 'System.Drawing.Bitmap' cannot be converted to 'Integer'. E:\Users\John Doe\documents\visual studio 2010\Projects\UN Client\UN Client\Form1.vb 388 13 UNClient
WITH .CUR: (runtime error)
Code:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.ArgumentException: Image format is not valid. The image file may be corrupted.
Parameter name: stream ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A01E1 (CTL_E_INVALIDPICTURE)
at System.Windows.Forms.UnsafeNativeMethods.IPersistStream.Load(IStream pstm)
at System.Windows.Forms.Cursor.LoadPicture(IStream stream)
--- End of inner exception stack trace ---
if someone could explain to me how to use .cur or .png my.resources files as custom mouse cursors then it would be greatly appreciated.
Re: .cur from resource file / memory stream
If you want to create a Cursor from a resource then you have to have added a cursor to the resource in the first place, not an image. You need to use an application that can generate CUR files. You can just use regular image files like BMP, JPG or PNG. They are not cursors.
Re: .cur from resource file / memory stream
jmc - i DO have it added as a resource. and set it to EMBEDED RESOURCE.
i added them in the formats of .cur and .png and neither work.
edit:
Code:
Dim ms As New System.IO.MemoryStream(My.Resources.rCurAttack)
Me.Cursor = New Cursor(ms)
rCurAttack is a real .cur file added in via the resources tab. properties changed to "Embedded Resource"
it produces the runtime error.
Re: .cur from resource file / memory stream
Quote:
Originally Posted by
Waxy
jmc - i DO have it added as a resource. and set it to EMBEDED RESOURCE.
i added them in the formats of .cur and .png and neither work.
edit:
Code:
Dim ms As New System.IO.MemoryStream(My.Resources.rCurAttack)
Me.Cursor = New Cursor(ms)
rCurAttack is a real .cur file added in via the resources tab. properties changed to "Embedded Resource"
it produces the runtime error.
And what is the data type of My.Resources.rCurAttack? Could it be that it's already type Cursor?
1 Attachment(s)
Re: .cur from resource file / memory stream
it doesn't recognize it as a cursor.
Code:
Me.Cursor = My.Resources.rCurAttack
Code:
Error 1 Value of type '1-dimensional array of Byte' cannot be converted to 'System.Windows.Forms.Cursor'. E:\Users\John Doe\documents\visual studio 2010\Projects\UN Client\UN Client\Form1.vb 391 21 UNClient
that's why i was trying some tutorials and came out with that example poping up over and over again on the magic google. :(
are only certain cursor formats recognized? it's a 32x32 cursor.
EDIT:
attached: the cursor .cur and .png as zip
Attachment 99313
Re: .cur from resource file / memory stream
OK then, so what happens when you execute the code that you posted in post #3?
Re: .cur from resource file / memory stream
#3 produces run time error:
Code:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.ArgumentException: Image format is not valid. The image file may be corrupted.
Parameter name: stream ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A01E1 (CTL_E_INVALIDPICTURE)
at System.Windows.Forms.UnsafeNativeMethods.IPersistStream.Load(IStream pstm)
at System.Windows.Forms.Cursor.LoadPicture(IStream stream)
--- End of inner exception stack trace ---
i just got done converting it to 24 bit (down from 32) and it produces the same error.
Re: .cur from resource file / memory stream
This is a bit of a guess but try setting the Position of the MemoryStream to zero before creating the Cursor.
Re: .cur from resource file / memory stream
Code:
Dim ms As New System.IO.MemoryStream(My.Resources.rCurAttack)
ms.Position = 0
Me.Cursor = New Cursor(ms)
error is the same.
cursor is attached in #5 (32 bit version)
Re: .cur from resource file / memory stream
Found a solution that works.
it doesn't explain what's wrong with the .CUR file or code, but it does give me a working solution:
Use-Icons-for-cursors-not-CUR
not the slick result i wanted, but it does work.