110,536
社区成员
发帖
与我相关
我的任务
分享
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 WindowsApplication48
{
public partial class Form1 : Form
{
[DllImport("User32.dll", EntryPoint = "PostMessage")]
static extern int PostMessage(IntPtr hwnd, int Msg, IntPtr wParam, string lParam);
[DllImport("User32.dll ")]
static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childe, string strclass, string strname);
const int WM_CLICK = 0x00F5;
String lpszName_Submit = "保存(&S)";
public Form1()
{
InitializeComponent();
Button AcceptButton = new Button();
AcceptButton.Text = lpszName_Submit;
AcceptButton.Parent = this;
AcceptButton.Click += new EventHandler(B_Click);
Button PostMessageButton = new Button();
PostMessageButton.Text = "发送消息";
PostMessageButton.Parent = this;
PostMessageButton.Click += new EventHandler(PostMessageButton_Click);
PostMessageButton.Location = Point.Add(AcceptButton.Location, new Size(100, 0));
}
void B_Click(object sender, EventArgs e)
{
MessageBox.Show("AcceptButton按钮收到消息");
}
void PostMessageButton_Click(object sender, EventArgs e)
{
// 我这里就直接把这个窗口的句柄当父句柄了
IntPtr EdithWnd = FindWindowEx(this.Handle, IntPtr.Zero, null, lpszName_Submit);
PostMessage(EdithWnd, WM_CLICK, IntPtr.Zero, null);
}
}
}