开发者

Using a Windows.Forms.Cursor for a WPF Cursor?

I have a System.Windows.Forms.Cursor with me and wanted to 开发者_如何学运维assign it to a WPF's image.Cursor property which happens to be of System.Windows.Input.Cursor type. The constraint here is, the former Cursor type is returned by our Framework and i can in no way modify it. Is there any way of casting the former to latter?


This did the trick for me:

SafeFileHandle panHandle = new SafeFileHandle(System.Windows.Forms.Cursors.PanNorth.Handle, false);
this.Cursor = System.Windows.Interop.CursorInteropHelper.Create(panHandle);

Documentation for SafeFileHandle warns against using false for the second arg but I got SEHExceptions no matter what if I used true (even if I used Cursors.PanNorth.CopyHandle())


I avoided SEHExceptions by this:

this.panHandle?.Close();
this.panHandle = new SafeFileHandle(System.Windows.Forms.Cursors.PanNorth.Handle, false);
this.Cursor = System.Windows.Interop.CursorInteropHelper.Create(panHandle);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜