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 鼠标控制 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("User32")] public extern static void SetCursorPos(int x, int y);//声明外部函数,移动到x,y位置 [DllImport("User32")] public extern static bool GetCursorPos(ref Point lpPoint);//获取当前鼠标位置信息 private void button1_Click(object sender, EventArgs e) { if (textBox_x.Text == "" || textBox_y.Text == "") { MessageBox.Show("请输入正确的坐标!!!", "错误"); return; } SetCursorPos(int.Parse(textBox_x.Text), int.Parse(textBox_y.Text)); } Point p = new Point(1, 1); private void timer1_Tick(object sender, EventArgs e) { GetCursorPos(ref p); label_pos.Text = "X:" + p.X + "\r\nY" + p.Y; } private void label_x_Click(object sender, EventArgs e) { } } }
希望对大家有所帮助,,,,<^_^>!!