(转载)c# winform 用子窗体刷新父窗体,子窗体改变父窗体控件的值
第一种方法:
用委托,Form2和Form3是同一组
Form2
C#代码
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
C#代码:
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();
}
}
}
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;
}
}
}
文章转载来源:http://heisetoufa.iteye.com/blog/382684
第二种方法已经试过,不错!
(转载)c# 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!";就搞定了,但是如果在一个新线程中这么 ...
- [转]- Winform 用子窗体刷新父窗体,子窗体改变父窗体控件的值
转自:http://heisetoufa.iteye.com/blog/382684 第一种方法: 用委托,Form2和Form3是同一组 Form2 using System; using Sys ...
- C#多线程应用:子线程更新主窗体控件的值(二)
在上篇文章中,我已经给大家列了一个在主线程中实现的方式,这篇文章来给大家说说使用Invoke的方式的例子: 对于不代理不太熟悉的朋友,建议先查查相关资料: 例子一: 在C#中,直接在子线程中对窗体上的 ...
- WinForm用户自定义控件,在主窗体加载时出现闪烁;调用用户控件出现闪烁,需要鼠标才能够显示
转载自:http://www.dotblogs.com.tw/rainmaker/archive/2012/02/22/69811.aspx 解决方案: 在调用用户控件的窗体里面添加一下代码: pro ...
- 【2017-05-02】winform弹出警告框选择性操作、记事本制作、对话框控件和输入输出流
一.winform弹出警告框选择性操作 MessageBox.Show()返回一个枚举类值(第一个参数为弹出窗口显示的内容,第二个参数为弹出窗口的标题,第三个参数为弹出窗口包含的按钮) 先新建一个变量 ...
- datagridview随窗体的大小而变,表格填满控件
在C#winform布局的时候,我们拖一个datagridview到窗体上面,将datagridview调整为适合窗体的大小,但是我们运行之后,点击最大化按钮的时候,却发现datagridview的大 ...
随机推荐
- squid日志配置与轮询
squid日志分类及参数 SQUID默认的log文件非常多,其中最重要的LOG日志有三个,分别为access.log.store.log.cache.log.三个日志的记录的内容如下: access. ...
- oracle10G/11G官方下载地址集合 直接迅雷下载
Oracle Database 11g Release 2 (11.2.0.1.0) for Microsoft Windows (64-bit) http://download.oracle.c ...
- 【JAVA、C++】LeetCode 005 Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- border-box
box-sizing属性可以为三个值之一:content-box(default),border-box,padding-box. content-box,border和padding不计算入wi ...
- 当Android工程中提示你找不到头文件,但你已经设置头文件路径了
虽然在Android.mk文件中,配置了LOCAL_C_INCLUDES路径,但是工程中的红色叉号一直提示找不到头文件 这时,你在工程树目录中展开Includes项,捣鼓捣鼓,重新build下,或许就 ...
- kail ip配置
设置ip /etc/network/interfaces # This file describes the network interfaces available on your system # ...
- Controller与View之间的数据传递
1)Controller向View传递数据ViewData["message"] = "Hello";//使用ViewData传递数据ViewBag.Time ...
- tuple元组(C++11及以后,如C++14)
类tuple与array最本质的区别当数tuple元组元素类型可以不一样,而统一数组array的元素类型必须一样. 本文主要举例: tuple_size Example 123456789101112 ...
- 查看LINUX当前负载
Linux的负载高,主要是由于CPU使用.内存使用.IO消耗三部分构成.任意一项使用过多,都将导致服务器负载的急剧攀升. [root@ok Desktop]# w 20:41:47 up 2:48, ...
- OAuth2 通用组件源码下载(支持新浪微博、QQ、淘宝)(转载)
转载地址:http://www.cyqdata.com/download/article-detail-54302 OAuth2 社区通用组件说明: 源码为C#(.NET)写成,目前支持新浪微博. ...