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.