在实际应用中,很多时候需要在多个窗体间进行传值,而在winform 中所有成员都是私有的,在子窗体中无法访问.通过委托和事件就可以进行一个函数的回调.具体代码如下:
主窗体:FrmNotePad
namespace Notepad
{
public partial class FrmNotePad : Form
{
private int count = 0;
public FrmNotePad()
{
InitializeComponent();
}
private void FrmNotePad_Load(object sender, EventArgs e)
{
}
private void FrmNotePad_Resize(object sender, EventArgs e)
{
txtContent.Width = this.Width - 10;
txtContent.Height = this.Height;
}
private void menuWarp_Click(object sender, EventArgs e)
{
menuWarp.Checked = true;
txtContent.WordWrap = true;
count++;
if (count % 2==0)
{
menuWarp.Checked = false;
txtContent.WordWrap = false;
}
} [Page]
private void menuFont_Click(object sender, EventArgs e)
{
NotepadFont myFont = new NotepadF