[转]- Winform 用子窗体刷新父窗体,子窗体改变父窗体控件的值
转自:http://heisetoufa.iteye.com/blog/382684
第一种方法:
用委托,Form2和Form3是同一组
Form2
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace TestMouseMove
- {
- public delegate void SetVisiableHandler();
- public partial class Form2 : Form
- {
- public Form2()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Form3 frm = new Form3(new SetVisiableHandler(SetVisiable));
- frm.Show();
- }
- private void SetVisiable()
- {
- SetVisiable(this.label1, !this.label1.Visible);
- }
- private void SetVisiable(Control control, bool visiable)
- {
- if (this.Controls.Contains(control))
- {
- control.Visible = visiable;
- }
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace TestMouseMove
- {
- public delegate void SetVisiableHandler();
- public partial class Form2 : Form
- {
- public Form2()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Form3 frm = new Form3(new SetVisiableHandler(SetVisiable));
- frm.Show();
- }
- private void SetVisiable()
- {
- SetVisiable(this.label1, !this.label1.Visible);
- }
- private void SetVisiable(Control control, bool visiable)
- {
- if (this.Controls.Contains(control))
- {
- control.Visible = visiable;
- }
- }
- }
- }
Form3
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace TestMouseMove
- {
- public partial class Form3 : Form
- {
- private SetVisiableHandler m_setVisible;
- public Form3(SetVisiableHandler setvisible)
- {
- InitializeComponent();
- this.m_setVisible = setvisible;
- }
- private void btnVisible_Click(object sender, EventArgs e)
- {
- if (this.m_setVisible != null)
- {
- this.m_setVisible();
- }
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace TestMouseMove
- {
- public partial class Form3 : Form
- {
- private SetVisiableHandler m_setVisible;
- public Form3(SetVisiableHandler setvisible)
- {
- InitializeComponent();
- this.m_setVisible = setvisible;
- }
- private void btnVisible_Click(object sender, EventArgs e)
- {
- if (this.m_setVisible != null)
- {
- this.m_setVisible();
- }
- }
- }
- }
第二种方法:
用变量,Form4和Form5是同一组
Form4
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace TestMouseMove
- {
- public partial class Form4 : Form
- {
- public Form4()
- {
- InitializeComponent();
- }
- #region 子窗口刷新父窗口的值
- private string strLabel1 = "";
- public string StrLabel1
- {
- get
- {
- return strLabel1;
- }
- set
- {
- strLabel1 = value;
- this.label1.Text = strLabel1;
- }
- }
- #endregion
- private void button1_Click(object sender, EventArgs e)
- {
- Form5 form5 = new Form5(this);//这里注意传个this
- form5.Show();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace TestMouseMove
- {
- public partial class Form4 : Form
- {
- public Form4()
- {
- InitializeComponent();
- }
- #region 子窗口刷新父窗口的值
- private string strLabel1 = "";
- public string StrLabel1
- {
- get
- {
- return strLabel1;
- }
- set
- {
- strLabel1 = value;
- this.label1.Text = strLabel1;
- }
- }
- #endregion
- private void button1_Click(object sender, EventArgs e)
- {
- Form5 form5 = new Form5(this);//这里注意传个this
- form5.Show();
- }
- }
- }
Form5
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace TestMouseMove
- {
- public partial class Form5 : Form
- {
- Form4 form4 = new Form4();
- public Form5(Form4 formFrm)//这个构造方法里有参数
- {
- form4 = formFrm; //这个必须要有
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- form4.StrLabel1 = this.textBox1.Text;
- }
- }
- }
[转]- Winform 用子窗体刷新父窗体,子窗体改变父窗体控件的值的更多相关文章
- c# winform 在一个窗体中使用另一个窗体中TextBox控件的值——解决办法
[前提]一个winform应用程序项目中,窗体B,需要使用 窗体A 中一个TextBox控件的值,进行计算等操作. [解决方案] 1.在窗体A中定义:public static double a;// ...
- Winform开发框架之客户关系管理系统(CRM)的开发总结系列4-Tab控件页面的动态加载
在前面介绍的几篇关于CRM系统的开发随笔中,里面都整合了多个页面的功能,包括多文档界面,以及客户相关信息的页面展示,这个模块就是利用DevExpress控件的XtraTabPage控件的动态加载实现的 ...
- Winform中实现更改DevExpress的RadioGroup的选项时更改其他控件(TextEdit、ColorPickEdit)的值
场景 Winform中实现读取xml配置文件并动态配置ZedGraph的RadioGroup的选项: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article ...
- WinForm/Silverlight多线程编程中如何更新UI控件的值
单线程的winfom程序中,设置一个控件的值是很easy的事情,直接 this.TextBox1.value = "Hello World!";就搞定了,但是如果在一个新线程中这么 ...
- (转载)c# winform 用子窗体刷新父窗体,子窗体改变父窗体控件的值
第一种方法: 用委托,Form2和Form3是同一组 Form2 C#代码 using System; using System.Collections.Generic; using System.C ...
- C#多线程应用:子线程更新主窗体控件的值(二)
在上篇文章中,我已经给大家列了一个在主线程中实现的方式,这篇文章来给大家说说使用Invoke的方式的例子: 对于不代理不太熟悉的朋友,建议先查查相关资料: 例子一: 在C#中,直接在子线程中对窗体上的 ...
- WinForm用户自定义控件,在主窗体加载时出现闪烁;调用用户控件出现闪烁,需要鼠标才能够显示
转载自:http://www.dotblogs.com.tw/rainmaker/archive/2012/02/22/69811.aspx 解决方案: 在调用用户控件的窗体里面添加一下代码: pro ...
- datagridview随窗体的大小而变,表格填满控件
在C#winform布局的时候,我们拖一个datagridview到窗体上面,将datagridview调整为适合窗体的大小,但是我们运行之后,点击最大化按钮的时候,却发现datagridview的大 ...
- 如何实现能像windows 窗体一样改变大小的控件 Silverlight
众所周知,我们可以将鼠标放在windows窗体的边框上,按住鼠标左键改变窗体大小.那么,在silverlight上如何实现呢? 1. 需要将改控件放置在canvas上. 2. 判断鼠标位置,然后将Ar ...
随机推荐
- 【CSS3】---阴影 box-shadow
box-shadow是向盒子添加阴影.支持添加一个或者多个.实现了投影效果 语法: box-shadow: X轴偏移量 Y轴偏移量 [阴影模糊半径] [阴影扩展半径] [阴影颜色] [投影方式] 参数 ...
- DWZ (JUI) 教程 tree 控件的选中事件
DWZ (JUI) 教程 tree 控件的选中事件 先简单说一下流程 第一步 当然是先定义好回调事件了 function checkCallback(json){ ........... ...... ...
- [Fiddler]Unable to Generate Certificate
I'm using Fiddler2 (or trying) to capture SSL traffic for a windows desktop gadget hitting an https ...
- phpstorm使用svn爆出“cannot load supported formats” 的解决
从这 http://subversion.apache.org/packages.html 下载svn客户端二进制包后修改phpstorm配置中 svn的指向到你的svn可执行程序即可解决
- 项目中重新引用WCF报错
今天在一个项目里,重新更新WCF引用的时候,居然报错了,提示根本找不到那个WCF接口,我赶紧跑去新建了一个空项目,试着用相同的地址引用一下,发现是可以的,完全ok 既然是虚惊一场,那就得想办法把这个W ...
- 第八篇、封装NSURLSession网络请求框架
主要功能介绍: 1.GET请求操作 2.POST请求操作 1.处理params参数(例如拼接成:usename="123"&password="123" ...
- iOS 自定义view里实现控制器的跳转
1.view里实现控制器的modal 拿到主窗口的根控制器,用根控制器进行modal需要的modal的控制器 场景:点击自定义view里的按钮实现控制器的modal UIViewController ...
- python基础:day3作业
修改haproxy配置文件 基本功能:1.获取记录2.添加记录3.删除记录 代码结构:三个函数一个主函数 知识点:1.python简单数据结构的使用:列表.字典等 2.python两个模块的使用:os ...
- nyoj71--独木舟上的旅行
描述 进行一次独木舟的旅行活动,独木舟可以在港口租到,并且之间没有区别.一条独木舟最多只能乘坐两个人,且乘客的总重量不能超过独木舟的最大承载量.我们要尽量减少这次活动中的花销,所以要找出可以安置所有旅 ...
- 济南学习 Day1 T2 pm
[问题描述]栈是一种强大的数据结构,它的一种特殊功能是对数组进行排序.例如,借助一个栈,依次将数组 1,3,2 按顺序入栈或出栈,可对其从大到小排序:1 入栈:3 入栈:3 出栈:2 入栈:2 出栈: ...