Using the Windows Drag Copy cursor

2020-04-21 06:33发布

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.

标签: c# .net winforms
1条回答
够拽才男人
2楼-- · 2020-04-21 07:22

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);
}
查看更多
登录 后发表回答