第一种方法:

用委托,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. UML基础:统一建模语言简介

    目录 背景知识 用例图 类图 序列图 状态图 活动图 组件图 部署图 结束语 英文原文:UML basics: An introduction to the Unified Modeling Lang ...

  2. 面向侧面的程序设计AOP-------《三》.Net平台AOP技术概览

    本文转载自张逸:晴窗笔记 .Net平台与Java平台相比,由于它至今在服务端仍不具备与unix系统的兼容性,也不具备类似于Java平台下J2EE这样的企业级容器,使得.Net平台在大型的企业级应用上, ...

  3. Repeated DNA Sequences

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  4. 查看ecshop广告位对应的广告详细信息

    在ecshop的日常应用中,如果添加了很多广告位和广告.然而时间一长又不知道哪些广告是有用的,哪些广告是没用的,广告对应的链接是什么.倘若人工一个个查看又特费时费力不讨好.因而想想办法用sql一次性查 ...

  5. 【JAVA、C++】LeetCode 021 Merge Two Sorted Lists

      Merge two sorted linked lists and return it as a new list. The new list should be made by splicing ...

  6. 8.python笔记之面向对象基础

    title: 8.Python笔记之面向对象基础 date: 2016-02-21 15:10:35 tags: Python categories: Python --- 面向对象思维导图 (来自1 ...

  7. springJDBC实现查询方法二

    无废话,看代码: @Override public List<Sites> queryAllSites(Pager pager) { String sql = "select * ...

  8. 用于主题检测的临时日志(ba86b8a0-7ed7-4b0b-bf1f-ce41aa2a5780 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)

    这是一个未删除的临时日志.请手动删除它.(ea9f667f-3be0-45c8-ad82-3acf819d571c - 3bfe001a-32de-4114-a6b4-4005b770f6d7)

  9. 二进制日志BINARY LOG清理

    mysql> show master logs; +------------------+-----------+ | Log_name | File_size | +------------- ...

  10. Stringbuffer与Stringbuilder源码学习和对比

    >>String/StringBuffer/StringBuilder的异同 (1)相同点观察源码会发现,三个类都是被final修饰的,是不可被继承的.(2)不同点String的对象是不可 ...