Home > Backend Development > C#.Net Tutorial > 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)

黄舟
Release: 2017-03-14 13:40:06
Original
2206 people have browsed it

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 the Resources 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 private variable in Form1 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
Copy after login

Add WindowsAPIStatement:

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

Add a method to obtain the cursor from existing resources:

        /// <summary>
        /// 从已有资源中获得光标
        /// </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;
        }
Copy after login

Add window initializationEvent handlingProgram, add a custom cursor:

        /// <summary>
        /// 窗口初始化事件处理程序
        /// </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);
        }
Copy after login

Set the default cursor, handle the cursor status :

Add in the else condition of the ShowForm method :

this.Cursor = cursorDefault;
Copy after login
Copy after login

Add code in the ExitCutImage method:

this.Cursor = cursorDefault;
Copy after login
Copy after login

Add the mouse to enter the Form1 form event handler:

        /// <summary>
        /// 鼠标进入Form1窗体事件处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_MouseEnter(object sender, EventArgs e)
        {
            this.Cursor = cursorDefault;
        }
Copy after login

Form1's constructor Add code:

Form1_Init();
Copy after login

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

Multiple cursor files have been added here, but only one is used. Others will 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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template