第一种方法:

用委托,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 用子窗体刷新父窗体,子窗体改变父窗体控件的值的更多相关文章

  1. c# winform 在一个窗体中使用另一个窗体中TextBox控件的值——解决办法

    [前提]一个winform应用程序项目中,窗体B,需要使用 窗体A 中一个TextBox控件的值,进行计算等操作. [解决方案] 1.在窗体A中定义:public static double a;// ...

  2. Winform开发框架之客户关系管理系统(CRM)的开发总结系列4-Tab控件页面的动态加载

    在前面介绍的几篇关于CRM系统的开发随笔中,里面都整合了多个页面的功能,包括多文档界面,以及客户相关信息的页面展示,这个模块就是利用DevExpress控件的XtraTabPage控件的动态加载实现的 ...

  3. Winform中实现更改DevExpress的RadioGroup的选项时更改其他控件(TextEdit、ColorPickEdit)的值

    场景 Winform中实现读取xml配置文件并动态配置ZedGraph的RadioGroup的选项: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article ...

  4. WinForm/Silverlight多线程编程中如何更新UI控件的值

    单线程的winfom程序中,设置一个控件的值是很easy的事情,直接 this.TextBox1.value = "Hello World!";就搞定了,但是如果在一个新线程中这么 ...

  5. [转]- Winform 用子窗体刷新父窗体,子窗体改变父窗体控件的值

    转自:http://heisetoufa.iteye.com/blog/382684 第一种方法: 用委托,Form2和Form3是同一组 Form2  using System; using Sys ...

  6. C#多线程应用:子线程更新主窗体控件的值(二)

    在上篇文章中,我已经给大家列了一个在主线程中实现的方式,这篇文章来给大家说说使用Invoke的方式的例子: 对于不代理不太熟悉的朋友,建议先查查相关资料: 例子一: 在C#中,直接在子线程中对窗体上的 ...

  7. WinForm用户自定义控件,在主窗体加载时出现闪烁;调用用户控件出现闪烁,需要鼠标才能够显示

    转载自:http://www.dotblogs.com.tw/rainmaker/archive/2012/02/22/69811.aspx 解决方案: 在调用用户控件的窗体里面添加一下代码: pro ...

  8. 【2017-05-02】winform弹出警告框选择性操作、记事本制作、对话框控件和输入输出流

    一.winform弹出警告框选择性操作 MessageBox.Show()返回一个枚举类值(第一个参数为弹出窗口显示的内容,第二个参数为弹出窗口的标题,第三个参数为弹出窗口包含的按钮) 先新建一个变量 ...

  9. datagridview随窗体的大小而变,表格填满控件

    在C#winform布局的时候,我们拖一个datagridview到窗体上面,将datagridview调整为适合窗体的大小,但是我们运行之后,点击最大化按钮的时候,却发现datagridview的大 ...

随机推荐

  1. iOS 和 Android 中的后台运行问题

    后台机制的不同,算是iOS 和 Android的一大区别了,最近发布的iOS7又对后台处理做了一定的更改,找时间总结一下编码上的区别,先做个记录. 先看看iOS的把,首先需要仔细阅读一下Apple的官 ...

  2. WINDOWS xp用户账户怎么没了怎么办?

    这是因为系统的一个默认设置!新建用户会把管理员用户隐藏!只是修改了里面的注册表!在运行(windows徽标+R)里输入“regedit”可以打开注册表编辑器,定位到“HKEY_LOCAL_MACHIN ...

  3. 【转载】C++ 值传递、指针传递、引用传递详解

    原文链接:http://www.cnblogs.com/yanlingyin/ 值传递: 形参是实参的拷贝,改变形参的值并不会影响外部实参的值.从被调用函数的角度来说,值传递是单向的(实参->形 ...

  4. int *p()与int (*p)()的区别

    int *p()是返回指针的函数 int (*p)()是指向函数的指针   返回指针的函数: int *a(int x,int y); 有若干个学生的成绩(每个学生有4门课程),要求在用户输入学生序号 ...

  5. 二、JavaScript语言--JS基础--JavaScript进阶篇--函数

    1.什么是函数 函数的作用,可以写一次代码,然后反复地重用这个代码. 如:我们要完成多组数和的功能. var sum; sum = 3+2; alert(sum); sum=7+8 ; alert(s ...

  6. Git入门学习和应用笔记

    >>关于Git 1.BitMover公司收回Linux社区的BitKeeper免费使用权,Linus花了两周时间自己用C写了一个分布式版本控制系统,这就是Git.2.什么是集中式版本控制系 ...

  7. h5 canvas 小球移动

    h5 canvas 小球移动 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  8. Visual Studio一秒变Node.js IDE

    (此文章同时发表在本人微信公众号"dotNET每日精华文章") 上个月微软发布了一个插件,可以让Visual Studio一秒变身最强大的Node.js开发工具.现在源代码移到了G ...

  9. Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset

    Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  10. 建模算法(二)——整数规划

    一.概述 1.定义:规划中变量部分或全部定义成整数是,称为整数规划. 2.分类:纯整数规划和混合整数规划. 3.特点: (1)原线性规划有最优解,当自变量限制为整数后: a.原最优解全是整数,那最优解 ...