打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
c# winform 用子窗体刷新父窗体,子窗体改变父窗体控件的值两种方法

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

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Winform中怎样在工具类中对窗体中多个控件进行操作(赋值)
C#,winform,ShowDialog,子窗体向父窗体传值
C#中的跨线程调用
C# 窗体封装为dll文件供另一个项目窗体调用
C# winform 在一个窗体中如何设置另一个窗体的TextBox的值
VS2008中C#调用Matlab生成的DLL文件
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服