Using Cursors in VB? - RealWorld forums

Log-in or register.

Using Cursors in VB?

Cursor Problem
The Spud
on September 11th 2008

Is it possible to use Real World cursors in Visual Basic applications?
I get the following error message:
"Image format is not valid. The image file may be corrupted. Parameter name: stream"
Any help would be appreciated, Thanks

Vlasta
on September 11th 2008

I did not try that myself, but it should be possible. What kind of cursor (static, animated, color depth) did you try to use and how?

Anonymous
on September 12th 2008

I just made a simple black and white static cursor (that I named "NewArrow") as a trial, and used the following code:

   Dim Cur As New Cursor("C:\Documents and Settings\Administrator\My Documents\My Pictures\NewArrow.cur")

   Windows.Forms.Cursor.Current = Cur

I also tried using cursors from the RealWorld Cursor Editor library without success. However, when I tried a custom made cursor (that was included with a program that I had downloaded) using the same VB code it worked.

The Spud
on September 12th 2008

Sorry, Forgot to log on before posting previous message. Also seem to be having some kind of smiley problem with my brackets.

Vlasta
on September 12th 2008

Did a couple of test with C# and yes, you are right. .NET cannot load any cursor except black and white (you need to select monochromatic format when creating the cursor in the editor) with its native methods. I thought the later versions of the .net framework were better, but it still sucks after 5 years of development...

Here is a workaround in C#, which should be easy to transform to VB code.

[System.Runtime.InteropServices.DllImport("user32.dll" )]
static extern IntPtr LoadCursorFromFile(string fileName);

IntPtr colorCursorHandle = LoadCursorFromFile("your-cursor.cur" );
Cursor.GetType().InvokeMember("handle", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.SetField, null, this.Cursor, new object[] { colorCursorHandle });
The Spud
on September 14th 2008

Changed my cursor to monochromatic and it works fine. Haven't been able to figure out the workaround in VB yet, but I'll get there eventually.
Thanks for your help, much appreciated.

Page views: 13095       Posts: 6      
Select background
Vista & Win 7 icons
I wish there were...