C# 隐藏和显示鼠标

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;



namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll", EntryPoint = "ShowCursor", CharSet = CharSet.Auto)]
        public static extern int ShowCursor(int status);

        public Form1()
        {
            InitializeComponent();
        }

        /// 
        /// 隐藏鼠标
        /// 
        /// 
        /// 
        private void button1_Click(object sender, EventArgs e)
        {
            while (ShowCursor(0) >= 0)
            {
                ShowCursor(0);
            }
                
        }

        /// 
        /// 显示鼠标
        /// 
        /// 
        /// 
        private void button2_Click(object sender, EventArgs e)
        {
            while (ShowCursor(1) < 0)
            {
                ShowCursor(1);
            }
        }
    }
}

 

你可能感兴趣的:(C#)