C# 获取和设置鼠标坐标

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

C# 获取和设置鼠标坐标运行界面:

代码:

using System;

using System.Collections.Generic;

using ponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;//

namespace mouseTest

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

///

///设置鼠标的坐标

///

///横坐标

///纵坐标

[DllImport("User32")]

public extern static void SetCursorPos(int x, int y);

///

///获取鼠标的坐标

///

///传址参数,坐标point类型

///获取成功返回真

[DllImport("User32")]

public extern static bool GetCursorPos(ref Point lpPoint);

Point p = new Point(1, 1);//定义存放获取坐标的point变量

private void button_go_Click(object sender, EventArgs e)

{

timer1.Start();

SetCursorPos(int.Parse(textBox_x.Text), (int.Parse(textBox_y.Text)));

}

private void timer1_Tick_1(object sender, EventArgs e)

{

GetCursorPos(ref p);

label_p.Text = "X:" + p.X + "\r\nY:" + p.Y;

if (Convert.ToInt16(p.X) > 560 && Convert.ToInt16(p.X) < 680 && Convert.ToInt16(p.Y) > 350 && Convert.ToInt16(p.Y) < 460)

pictureBox1.Visible = true;

else

pictureBox1.Visible = false;

}

}

}

源代码下载地址:/s/1jG9mqY6

相关文档
最新文档