添加2个WIN窗体,分别为 from1 form2 在form2中单击按钮来设置form1中按钮的标题
namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
}
}
}namespace WindowsFormsApplication9
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Form1.button1.text = "Button1"; //窗体2中单击按钮1如何设置窗体1中按钮1的标题?
}
}
}
窗体传值
namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
}
}
}namespace WindowsFormsApplication9
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Form1.button1.text = "Button1"; //窗体2中单击按钮1如何设置窗体1中按钮1的标题?
}
}
}
窗体传值
解决方案 »
- datagrivdview的下拉框值改变后,不显示改变后的值。
- 如何使用C#发送多封邮件?
- 无法加载 DLL“ftpdll.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。
- 关于多线程访问COM接口的问题
- c#web窗体中menu的问题
- 关于Label控件显示数据库的数据问题???
- md5
- 用<object id=sp1 classid=CLSID:0002E510-0000-0000-C000-000000000046 style="width:49%;height:350"></object>加上的组件,在后台代码
- 求助,关于scs
- 请问C#中的random如何使用
- 两套系统的数据同步问题,请朋友们帮忙
- 关于画画(重绘)的问题
那我就写一个给你吧,采用委托方式,具体委托的用法你可以参考教科书、msdn什么的都可以找到它的知识Form1namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.SetTitle += SeTitleHandler;
f2.Show();
} private void SeTitleHandler(object sender, CustomerArgs e)
{
button1.Text = e.Title;
}
}
}
Form2namespace WindowsFormsApplication2
{
public partial class Form2 : Form
{
public delegate void CustomerEventHandler(object sender,CustomerArgs e);
public event CustomerEventHandler SetTitle; public Form2()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
if (SetTitle != null)
{
SetTitle(this,new CustomerArgs("button1"));
}
}
} public class CustomerArgs : EventArgs
{
public string Title { get; private set; } public CustomerArgs(string title)
{
Title = title;
}
}
}
那我就写一个给你吧,采用委托方式,具体委托的用法你可以参考教科书、msdn什么的都可以找到它的知识Form1namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.SetTitle += SeTitleHandler;
f2.Show();
} private void SeTitleHandler(object sender, CustomerArgs e)
{
button1.Text = e.Title;
}
}
}
Form2namespace WindowsFormsApplication2
{
public partial class Form2 : Form
{
public delegate void CustomerEventHandler(object sender,CustomerArgs e);
public event CustomerEventHandler SetTitle; public Form2()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
if (SetTitle != null)
{
SetTitle(this,new CustomerArgs("button1"));
}
}
} public class CustomerArgs : EventArgs
{
public string Title { get; private set; } public CustomerArgs(string title)
{
Title = title;
}
}
}
虽然看不懂,但是好像很厉害的样子。