国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#實(shí)現(xiàn)winform用子窗體刷新父窗體及子窗體改變父窗體控件值的方法

2019-10-29 21:40:07
字體:
供稿:網(wǎng)友

這篇文章主要介紹了C#實(shí)現(xiàn)winform用子窗體刷新父窗體及子窗體改變父窗體控件值的方法,涉及C#窗體交互的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了C#實(shí)現(xiàn)winform用子窗體刷新父窗體及子窗體改變父窗體控件值的方法。分享給大家供大家參考。具體如下:

第一種方法:

用委托,Form2和Form3是同一組

Form2

 

 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8. namespace TestMouseMove  
  9. {  
  10. public delegate void SetVisiableHandler();  
  11. public partial class Form2 : Form  
  12. {  
  13. public Form2()  
  14. {  
  15. InitializeComponent();  
  16. }  
  17. private void button1_Click(object sender, EventArgs e)  
  18. {  
  19. Form3 frm = new Form3(new SetVisiableHandler(SetVisiable));  
  20. frm.Show();  
  21. }  
  22. private void SetVisiable()  
  23. {  
  24. SetVisiable(this.label1, !this.label1.Visible);  
  25. }  
  26. private void SetVisiable(Control control, bool visiable)  
  27. {  
  28. if (this.Controls.Contains(control))  
  29. {  
  30. control.Visible = visiable;  
  31. }  
  32. }  
  33. }  
  34. }  

Form3

 

 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8. namespace TestMouseMove  
  9. {  
  10. public partial class Form3 : Form  
  11. {  
  12. private SetVisiableHandler m_setVisible;  
  13. public Form3(SetVisiableHandler setvisible)  
  14. {  
  15. InitializeComponent();  
  16. this.m_setVisible = setvisible;  
  17. }  
  18. private void btnVisible_Click(object sender, EventArgs e)  
  19. {  
  20. if (this.m_setVisible != null)  
  21. {  
  22. this.m_setVisible();  
  23. }  
  24. }  
  25. }  
  26. }  

第二種方法:

用變量,Form4和Form5是同一組

Form4

 

 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8. namespace TestMouseMove  
  9. {  
  10. public partial class Form4 : Form  
  11. {  
  12. public Form4()  
  13. {  
  14. InitializeComponent();  
  15. }  
  16. #region 子窗口刷新父窗口的值  
  17. private string strLabel1 = "";  
  18. public string StrLabel1  
  19. {  
  20. get 
  21. {  
  22. return strLabel1;  
  23. }  
  24. set 
  25. {  
  26. strLabel1 = value;  
  27. this.label1.Text = strLabel1;  
  28. }  
  29. }  
  30. #endregion  
  31. private void button1_Click(object sender, EventArgs e)  
  32. {  
  33. Form5 form5 = new Form5(this);//這里注意傳個(gè)this  
  34. form5.Show();  
  35. }  
  36. }  
  37. }  

Form5

 

 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8. namespace TestMouseMove  
  9. {  
  10. public partial class Form5 : Form  
  11. {  
  12. Form4 form4 = new Form4();  
  13. public Form5(Form4 formFrm)//這個(gè)構(gòu)造方法里有參數(shù)  
  14. {  
  15. form4 = formFrm; //這個(gè)必須要有  
  16. InitializeComponent();  
  17. }  
  18. private void button1_Click(object sender, EventArgs e)  
  19. {  
  20. form4.StrLabel1 = this.textBox1.Text;  
  21. }  
  22. }  

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 漳州市| 韶山市| 沁源县| 赤壁市| 武山县| 曲水县| 馆陶县| 洛川县| 石城县| 安宁市| 衡阳市| 克山县| 乌兰察布市| 陆河县| 侯马市| 重庆市| 南宁市| 迁西县| 英山县| 安塞县| 澳门| 井研县| 大洼县| 永川市| 清水县| 沙湾县| 泸西县| 南华县| 碌曲县| 呼玛县| 亚东县| 梅州市| 商河县| 临朐县| 漯河市| 类乌齐县| 营口市| 安溪县| 岢岚县| 定远县| 佛教|