第一种方法:
用委托,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;   
            }   
        }   
  
    }   
}  

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();   
            }   
        }   
  
    }   
}  

第二种方法:
用变量,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;   
        }   
    }   
}  

转载于:https://www.cnblogs.com/arongbest/archive/2009/12/25/1632158.html

c# winform 用子窗体刷新父窗体,子窗体改变父窗体控件的值相关推荐

  1. Windows窗体学这一篇就够了(C#控件讲解)

    目录 一.Form窗体 1.1窗体的创建和删除 1.添加窗体 2.删除窗体 3.多窗体的使用 1.2.窗体属性 1.2.1更换窗体图标 1.2.2隐藏窗体的标题栏(FormBorderStyle属性) ...

  2. 窗体样式使用WS_EX_LAYERED后,无法绘制windows控件的解决办法

    根据一副png图片绘制半透明窗体时,用了WS_EX_LAYERED后当前窗体再也不会处理paint事件,所以所含的子控件是一辈子也不会画出来的,但是这个控件确实存在,而且可以响应事件 .而此时wind ...

  3. C#WinForm判断界面上多个TextBox控件的值是否为空

    说明:当WinForm界面上面有多个控件需要判断是否为空,如果用if(){}else,难免有些繁琐.在参考了其他博主的资料以后,我这里也做了一些整理,以TextBox控件示例,如下. VS打开创建一个 ...

  4. 刷新后控制TAB键到下一个控件

    页面上的控件能一直TAB下去,这是系统的一个很基本的要求.在网上没有搜索到相关的方法.我觉得一般做法都是使页面无刷新,但是如果遇到页面不得不刷新的情况,如何去控制呢?    思路是很简单的,首先是获取 ...

  5. 【Android归纳】基于XListView的下拉刷新、上拉加载更多的控件分析

    目录 前言 功能介绍 总体设计 组成 类关系图 详细设计 XlistViewHeader原理分析 XListViewFooter原理分析 XListView原理分析 代码带注释下载 目录 前言 如果你 ...

  6. java获取其他窗体上的控件,怎么获取从引用自定义panel控件的frame里获取它的控件的值...

    如何获取从引用自定义panel控件的frame里获取它的控件的值? 以下是自定义的panel控件: package snooker; import java.awt.Component; import ...

  7. winform窗体控件

    目录 1.窗体(Form) 2.Label (标签)控件 3.TextBox(文本框)控件 4.RichTextBox控件 5.NumericUpDown控件 6.Button(按钮)控件 7.Gro ...

  8. C# Winform 实现窗体无系统边框,但是具有系统边框的所有功能,同时保证控件不闪烁

    本人新手,想写个上位机,窗口能够实现最小化,最大化,拖动,改变大小等常用功能,Winform窗体的FormBorderStyle设置成sizable即可实现,但是窗体有自带的边框,不好看且无法编辑,想 ...

  9. WinForm窗体PropertyGrid控件的使用

    使用过 Microsoft Visual Basic 或 Microsoft Visual Studio .NET的朋友,一定使用过属性浏览器来浏览.查看或编辑一个或多个对象的属性..NET 框架 P ...

最新文章

  1. 双系统gazebo闪退_记录Ubuntu16.04下PX4联合Gazebo仿真时遇到的问题与解决方法
  2. android 拍照不能保存图片格式,Android 拍照后保存到手机里,在相册找不到
  3. Python+MySQL学习笔记(一)
  4. 使用ping命令查看网络延迟--用Enki学Linux系列(7)
  5. 数据结构与算法-- 数组中出现次数超过一半的数字(时间复杂度的讨论)
  6. linux 复制分区文件,dd复制分区后目标分区的大小变成原分区了
  7. python面向对象编程从零开始_Python面向对象编程从零开始,从没对象到有对象
  8. 微软和Wistron再度联手,Android和Chrome OS又成鱼肉
  9. 变压器绕组降低邻近效应_高功率UPS性能提升,规格/重量显著降低
  10. jquery内容过滤器:contains :empty :has(p) :parent
  11. [渝粤教育] 西南科技大学 西方现代派文学 在线考试复习资料
  12. 奇虎360开源其日志搜索引擎,可处理百万亿级的数据
  13. 西门子S7-200SMART PLC视频教程(百度网盘)
  14. 列宁名言、警句、格言、语录
  15. Themeforest 热卖 Shopify 主题 六折促销活动进行中
  16. torch.masked_select和torch.masked_scatter
  17. tair ldb存储引擎性能测试方案
  18. 2022年湖南省中医执业医师考试第二单元中医诊断学(四)
  19. 新浪微博 418 咖啡壶控制协议
  20. Python3,我用这种方式讲解python模块,80岁的奶奶都说能理解。建议收藏 ~ ~

热门文章

  1. asp.net中窗口相关操作总结(javascript)
  2. 防止IIS文件被下载方法
  3. 用C#操纵IIS(代码)
  4. 一维码ITF 25简介及其解码实现(zxing-cpp)
  5. 举例说明使用MATLAB Coder从MATLAB生成C/C++代码步骤
  6. 【Live555】live555源码详解(七):GenericMediaServer、RTSPServer、RTSPClient
  7. access“idno”字段改为文本型_结构化文本计算示例(一)
  8. c语言程序设计日历推后几天是星期几,C语言程序设计: 输入年月日 然后输出是星期几...
  9. db2 linux 数据导出_linux db2 导出数据库
  10. SpringSecurity学习:1(第一个SpringSecurity项目)