C # Development Example-Custom screenshot tool (ix) cursor with custom cursor and QQ screenshot

Source: Internet
Author: User
When using the function of QQ, do not think its cursor is cool? Just say it today. How to apply a custom cursor in our tool using the QQ cursor.

To open a resource:


To switch to a file resource view:


Open the Resource Files directory and copy the cursor files to this directory:


Required cursor File download:C # Software Development example. The cursor file used in a private custom-made screen tool

Select the resources directory, refresh, and display the cursor file just copied in:

Select the cursor file and drag to the file view of the resource:


The first letter of a word in a resource resource name is capitalized.

Cursor preview:


To add a private variable in the Form1 class:

        #region The custom cursor        System.Windows.Forms.Cursor cursorcross = null;        System.Windows.Forms.Cursor cursordefault = null;        System.Windows.Forms.Cursor cursortext = null;        System.Windows.Forms.Cursor cursorcolor = null;        #endregion

Add WindowsAPI declaration:

        [DllImport ("User32.dll")]        private static extern IntPtr Loadcursorfromfile (string fileName);

To add a method to get the cursor from an existing resource:

        <summary>////        get cursor from existing resources///</summary>//        <param name= "resource" ></param>        //<returns></returns> public static Cursor Getcursorfromresource (byte[] Resource)        {            Byte[] B = resource;            FileStream FileStream = new FileStream ("CursorData.dat", FileMode.Create);            FileStream.Write (b, 0, b.length);            Filestream.close ();            Cursor cur = new cursor (loadcursorfromfile ("CursorData.dat"));            return cur;        }

Add a window initialization event handler, and add a custom cursor:

        <summary>        ///Window initialization event handlers        ///</summary> private void Form1_init ()        {            This.iscuting = false;            This.beginpoint = new Point (0, 0);            This.endpoint = new Point (0, 0);            Cursordefault = Getcursorfromresource (Properties.Resources.Cursor_Default);            Cursorcross = Getcursorfromresource (Properties.Resources.Cursor_Cross);            Cursortext = Getcursorfromresource (Properties.Resources.Cursor_Text);            Cursorcolor = Getcursorfromresource (Properties.Resources.Cursor_Color);        }

Set the default cursor to handle cursor state:

In the else condition of the ShowForm method, add:

This. Cursor = Cursordefault;

Add code in the Exitcutimage method:

This. Cursor = Cursordefault;

Add mouse to enter the Form1 form event handler:

        <summary>///        mouse enters Form1 form event handler///</summary>//        <param name= "Sender" ></ Param>        //<param name= "E" ></param>        private void Form1_mouseenter (object sender, EventArgs e)        {this            . Cursor = Cursordefault;        }

Add code to the Form1 constructor:

Form1_init ();

Ok, compile, see the effect!

Multiple cursor files are added here, but only one is used, and the others are used in later additions.

Related Article

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.