. NET trap two erratic cursors

Source: Internet
Author: User

We need a lot of custom cursors in our software to make the necessary prompts in the user interaction process. We started by putting the cursor in a resource file and then loading it with code like this:

var cursor = new cursor (new MemoryStream (Resource.openhandicon));   
... ...   
if (usedefaultcursor)   
{control   
    . Cursor = Cursors.Default;   
}   
else
{control   
    . Cursor = Cursor;   
}

However, when a custom cursor should be displayed during the test, it is always replaced with success and sometimes unsuccessful.

It turns out to be. NET, the cursor constructor cannot load a cursor outside the Black-and-white color of the cursor class. However, you can bypass this restriction by following the code:

public static Cursor Loadresourcecursor (byte[] data   
{   
    var path = Path.gettempfilename ();   
    File.writeallbytes (path, data);   
    return new Cursor (Loadcursorfromfile (path));   
}   
       
[System.Runtime.InteropServices.DllImport ("User32.dll")]   
private static extern IntPtr Loadcursorfromfile (string fileName);

All cursors can be used normally after this process.

Source: http://www.cnblogs.com/brucebi/archive/2013/04/02/2995888.html

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.