[bo][un]sun_life[/un] 在 2008-10-23 09:32 的发言:[/bo]
你能给解释一下你代码的意思吗?我看不懂!
你能给解释一下你代码的意思吗?我看不懂!
我来解释下吧,我喜欢做这种事~不过4楼的兄弟确实太牛了,他的代码我研究了半个小时,才搞懂,下次记得自己要注释哈~免得我没把你的精华讲述出来浪费了。
程序代码:
using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication19 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Form2 fomr2; private void toolStripButton1_Click(object sender, EventArgs e) { fomr2 = new Form2(); fomr2.MdiParent = this; fomr2.OnShowMdiHandler += new Form2.ShowMDIForm2Handler(fomr2_OnShowMdiHandler);//把1这个事件处理函数,通过委托加入事件OnShowMdiHandler以后只要调用此事件就可以执行为form3指定父窗体之操作 fomr2.Show(); } void fomr2_OnShowMdiHandler(object sender) //form2的事件处理函数。 { //因为标记三的原因,程序进入这里,至此,form3终于成了form1的子窗体。。。好累。。。 Form3 form3 = (Form3)sender; form3.MdiParent = this; } private void Form1_Load(object sender, EventArgs e) { } } } using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication19 { public partial class Form2 : Form { public delegate void ShowMDIForm2Handler(object sender); public event ShowMDIForm2Handler OnShowMdiHandler; public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form3 form3 = new Form3(); form3.OnShowMDIForm3Handler += new Form3.ShowMDIForm3Handler(form3_OnShowMDIForm3Handler); //此句标记为一 form3.show(); //关键滴位置 F11,冲了。 } void form3_OnShowMDIForm3Handler(object sender) { OnShowMdiHandler(sender); //因为二,程序运行到这里,触发了此事件,标记为三,跳转至执行此事件的代码fomr2_OnShowMdiHandler() } } } using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication19 { public partial class Form3 : Form { public delegate void ShowMDIForm3Handler(object sender); public event ShowMDIForm3Handler OnShowMDIForm3Handler; public Form3() { InitializeComponent(); } public void show() { OnShowMDIForm3Handler(this); //把当前窗体form3对象传入事件OnShowMDIForm3Handler()因为一,因为一,所以程序去执行form3_OnShowMDIForm3Handler()这里标记为二,前往form3_OnShowMDIForm3Handler的代码 this.Show(); } private void Form3_Load(object sender, EventArgs e) { } } }
我头有点昏。。。你可曾听懂?
仁者乐膳,智者乐睡。我都爱~