.Net并没有提供改变鼠标指针位置、模拟点击操作的函数;但是Windows API提供了。其中一个是:
SetCursorPos(int X, int Y);
该函数可以改变鼠标指针的位置。其中X,Y是相对于屏幕左上角的绝对位置。另一个函数是:
mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);
调用如下:
private void Form1_Click(object sender, EventArgs e)
{
Mouse.SetCursorPos(200, 200);
}
不知道为什么.
SetCursorPos(int X, int Y);
该函数可以改变鼠标指针的位置。其中X,Y是相对于屏幕左上角的绝对位置。另一个函数是:
mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);
调用如下:
private void Form1_Click(object sender, EventArgs e)
{
Mouse.SetCursorPos(200, 200);
}
不知道为什么.
public static extern bool SetCursorPos(int x, int y); private void button6_Click(object sender, EventArgs e)
{
SetCursorPos(10, 10);
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace MouseApplication2
{
public partial class Form1 : Form
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool SetCursorPos(int x, int y); public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
SetCursorPos(10, 10); } }
}