70001468 I need to use a color cursor in my forma and VDF

Article 70001468
Type HowTo
Product Engine
Version 8
Date Added 12/14/2018
Fixed 8.8001.0.5 (12/14/2018)
Submitted by Deswik Jira


I need to use a color cursor in my forma and VDF but in both (form and VDF) the mouse pointer is shown black. How can I do this?


You need to use P/Invoke to use color cursors, as .NET supports only Black and White cursors. See the code below:

public static extern IntPtr LoadCursorFromFile(string filename);

    // .NET supports black and white cursors not color. To use color cursors, the P/Invoke should be used as suggested in MSDN
    Cursor mycursor = new Cursor(Cursor.Current.Handle);
    //cur3.cur color cursor (not black&white cusror) is in test folder 
    IntPtr colorcursorhandle = LoadCursorFromFile(@"C:\test\cur3.cur"); // this is a color Cursor
    mycursor.GetType().InvokeMember("handle", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField, null, mycursor, new object[] { colorcursorhandle });
    this.Cursor = mycursor; // set it to the Form
    vdFramedControl.BaseControl.SetCustomMousePointer(mycursor); // set it to the VDF component

Send comments on this topic.