using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
using System.Runtime.InteropServices;
public partial class Form1 : Form
{
#region API
[DllImport("user32.dll")]
static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);
[Flags]
enum MouseEventFlag : uint
{
Move = 0x0001,
LeftDown = 0x0002,
LeftUp = 0x0004,
RightDown = 0x0008,
RightUp = 0x0010,
MiddleDown = 0x0020,
MiddleUp = 0x0040,
XDown = 0x0080,
XUp = 0x0100,
Wheel = 0x0800,
VirtualDesk = 0x4000,
Absolute = 0x8000
}
#endregion
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("提交");
}
private void button1_Click(object sender, EventArgs e)
{
Point p=PointToScreen(button2.Location);;
// this.button2 .Location .X
SetCursorPos(p.X + 10, p.Y+10);
// mouse_event(MouseEventFlag.Move, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
//执行左键按下
mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
//执行左键松开
}
[DllImport("user32.dll")]
static extern bool SetCursorPos(int x, int y);
}
}