Search code examples
c#.netwinformsmouse-cursor

Using the Windows Drag Copy cursor


I can set a cursor like this:

Me.Cursor = Cursors.Cross

Using IntelliSense, I don't find this "Copy" cursor:

Copy Cursor

Is there any way to get it in a managed way? I wouldn't want to load a bitmap or so. I would like to leave that up to Windows as the user may have changed the cursor size or set a different color schema.


Solution

  • Drag and drop cursors belong ole32.dll. You can load them from that library. To do so, you need to load ole32.dll using LoadLibrary, then using LoadCursor get the handle of those cursors. You can use 1 to 7 as LoadCursor parameter to get cursors from ole32.dll. The cursor which you are looking for is 3 or 6:

    enter image description here

    [DllImport("kernel32.dll")]
    public static extern IntPtr LoadLibrary(string dllToLoad);
    
    [DllImport("user32.dll")]
    public static extern IntPtr LoadCursor(IntPtr hInstance, UInt16 lpCursorName);
    
    private void button1_Click(object sender, EventArgs e)
    {
        var l = LoadLibrary("ole32.dll");
        var h = LoadCursor(l, 6);
        this.Cursor = new Cursor(h);
    }