foreach (Control ctl in myForm.Controls)
{
if (ctl is Button && ctl.Text=="确定")
{
//发送该按钮的鼠标点击事件
}
}
我想遍历窗体myForm中的控件,找到一个text属性是"确定"的按钮,然后用代码实现点击该按钮。我该怎么做?
{
if (ctl is Button && ctl.Text=="确定")
{
//发送该按钮的鼠标点击事件
}
}
我想遍历窗体myForm中的控件,找到一个text属性是"确定"的按钮,然后用代码实现点击该按钮。我该怎么做?
或者按钮已经有响应函数的话 直接调用那个函数 button1_Click(this, EventArgs.Empty);
foreach (Control ctl in myForm.Controls)
{
if (ctl is Button && ctl.Text=="确定")
{
//发送该按钮的鼠标点击事件 buttonClickDelegate btnDelegate = new buttonClickDelegate(ClickFunction);
btnDelegate("YES");
}
} //定义委托
public delegate void buttonClickDelegate(string param);
/// <summary>
/// 处理按钮的鼠标点击事件 的函数
/// </summary>
/// <param name="param">参数</param>
protected void ClickFunction(string param)
{
//to do ...
}看看可是你需要的
如 this.Button1.Click(this,new EventArg());