WPF Creating a custom mouse cursor pointer

Source: Internet
Author: User

Two constructors in the WPF cursor class:

 Public Cursor (Stream cursorstream)  Public Cursor (string cursorfile)

The resources used by the above constructors are either ANI or cur files and do not support the way images are generated.

    ///This class allow you to create a Cursor form a Bitmap/// </summary>    Internal classBitmapcursor:safehandle { Public Override BOOLIsinvalid {Get            {                returnHandle = = (INTPTR) (-1); }        }         Public StaticCursor createbmpcursor (Bitmap cursorbitmap) {varc =Newbitmapcursor (CURSORBITMAP); returncursorinterophelper.create (c); }        protectedbitmapcursor (Bitmap cursorbitmap):Base((INTPTR) (-1),true) {Handle=Cursorbitmap.gethicon (); }        protected Override BOOLReleaseHandle () {BOOLresult =DestroyIcon (handle); Handle= (INTPTR) (-1); returnresult; } [DllImport ("User32")]        Private Static extern BOOLDestroyIcon (IntPtr hicon); }

Extension methods provided:

 public  static  Bitmap            Bitmapsourcetobitmap (this   BitmapSource source) {  using  (var  stream = new   MemoryStream ()) { var  e = new   Bmpbitmapencoder                ();                E.frames.add (bitmapframe.create (source));                E.save (stream);  var  bmp = new                  Bitmap (stream);             return   bmp; }        }

Transferred from: http://www.cnblogs.com/zhouyinhui/archive/2010/05/28/1746502.html

WPF Creating a custom mouse cursor pointer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.