Home>Article>Backend Development> C# development example-customized screenshot tool (9) using custom cursor and cursor when taking QQ screenshots (picture)

C# development example-customized screenshot tool (9) using custom cursor and cursor when taking QQ screenshots (picture)

黄舟
黄舟 Original
2017-03-14 13:40:06 2128browse

When using the screenshot function of QQ, do you think its cursor is cool? Today I will talk about how to apply a custom cursor and use the QQ screenshot cursor in our screenshot tool.

Open resource:


Switch to file resourceView:


Open the resource file directory and copy the cursor file to this directory:


Required cursorFile downloadC#Software development example. Customize the cursor file used in your own screenshot tool

Select theResources directory and refresh, Display the cursor file just copied in:

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


Resources The first letter of the word in the resource name is changed to uppercase.

Cursor preview:


Add privatevariableinForm1 class:

#region 自定义光标 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 WindowsAPIStatement:

[DllImport("user32.dll")] private static extern IntPtr LoadCursorFromFile(string fileName);

Add a method to obtain the cursor from existing resources:

///  /// 从已有资源中获得光标 ///  ///  ///  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 window initializationEvent handlingProgram, add a custom cursor:

///  /// 窗口初始化事件处理程序 ///  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, handle the cursorstatus:

Add in theelsecondition of the ShowForm method :

this.Cursor = cursorDefault;

Add code in the ExitCutImage method:

this.Cursor = cursorDefault;

Add the mouse to enter the Form1 form event handler:

///  /// 鼠标进入Form1窗体事件处理程序 ///  ///  ///  private void Form1_MouseEnter(object sender, EventArgs e) { this.Cursor = cursorDefault; }

Form1'sconstructorAdd code:

Form1_Init();

Ok, compile, take a screenshot to see the effect!

Multiple cursor files have been added here, but only one is used.Otherswill be used in functions added in the future.

The above is the detailed content of C# development example-customized screenshot tool (9) using custom cursor and cursor when taking QQ screenshots (picture). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn