Вот, придумал! На форме 2 кнопки: button1 и button2. При нажатии button1, программно нажимается button2.
| Код | using System; using System.ComponentModel; using System.Data; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Threading;
namespace WindowsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); button2.Click += new EventHandler(button2_Click); }
void button2_Click(object sender, EventArgs e) { MessageBox.Show("Button2 clicked!"); }
const uint WM_LBUTTONDOWN = 513; const uint WM_LBUTTONUP = 514; const int Period = 200; IntPtr NIL = new IntPtr();
[DllImport("user32.dll", CharSet = CharSet.Auto)] static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
private void button1_Click(object sender, EventArgs e) { SendMessage(button2.Handle, WM_LBUTTONDOWN, NIL, NIL); Application.DoEvents(); Thread.Sleep(Period); SendMessage(button2.Handle, WM_LBUTTONUP, NIL, NIL); } } }
|
|