110,534
社区成员
发帖
与我相关
我的任务
分享
public partial class Form1 : Form
{
Form2 f =null;
IDoMethod dm = null;
public Form1()
{
InitializeComponent();
f = new Form2();
dm = f as IDoMethod;
}
protected override void OnClick(EventArgs e)
{
if (dm != null)
{
dm.Run();
}
}
}
public interface IDoMethod
{
void Run();
}
//以下是form2的代码
public partial class Form2 : Form,IDoMethod
{
Button button1 = new Button();
public Form2()
{
InitializeComponent();
button1.Click += new EventHandler(button1_Click);
}
void button1_Click(object sender, EventArgs e)
{
Run();
}
#region IDoMethod Members
public void Run()
{
MessageBox.Show("Form2.Button1.OnClick");
}
#endregion
}
public partial class Form1 : Form
{
Form2 f =null;
IDoMethod dm = null;
public Form1()
{
InitializeComponent();
f = new Form2();
dm = f as IDoMethod;
}
protected override void OnClick(EventArgs e)
{
if (dm != null)
{
dm.Run();
}
}
}
public interface IDoMethod
{
void Run();
}
//以下是form2的代码
public partial class Form2 : Form,IDoMethod
{
Button button1 = new Button();
public Form2()
{
InitializeComponent();
button1.Click += new EventHandler(button1_Click);
}
void button1_Click(object sender, EventArgs e)
{
Run();
}
#region IDoMethod Members
public void Run()
{
MessageBox.Show("Form2.Button1.OnClick");
}
#endregion
}
public void button1_Click(object sender, EventArgs e)
{
}
Form2 form = new Form2();
form.button1_Click(null, null);
FrmSel form = new FrmSel();
form.MyEvent += new MyDelegate(form_MyEvent);
form.ShowDialog();
void form_MyEvent(string text, string tag)
{
txtcDepCode.Text = text;
txtcDepCode.Tag = tag;
}
//FrmSel.cs:
public delegate void MyDelegate(string text, string tag);
public partial class FrmSel : Form
{
public event MyDelegate MyEvent;
private void btnOK_Click(object sender, EventArgs e)
{
string tmpName = "aaaaaaaaa";
string tmpCode = "bbbbbbb";
this.MyEvent(tmpName, tmpCode);
this.Close();
}
}
FrmSel form = new FrmSel();
form.MyEvent += new MyDelegate(form_MyEvent);
form.ShowDialog();
void form_MyEvent(string text, string tag)
{
txtcDepCode.Text = text;
txtcDepCode.Tag = tag;
}
FrmSel.cs:
public delegate void MyDelegate(string text, string tag);
public partial class FrmSel : Form
{
public event MyDelegate MyEvent;
private void btnOK_Click(object sender, EventArgs e)
{
string tmpName = "aaaaaaaaa";
string tmpCode = "bbbbbbb";
this.MyEvent(tmpName, tmpCode);
this.Close();
}
}