原理:两个窗体绑定同一个静态对象。这里只是为了说明问题,并没进行静态对象进行清理方面的工作。

类结构图

程序运行效果如图

具体实现
MainForm.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    /**//// <summary>
    /// 主窗体
    /// </summary>
    public class MainForm:Form
    {
        private Button button1;
        private Label label1;

        private TextBox textBox1;

        public MainForm()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(116, 12);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(164, 21);
            this.textBox1.TabIndex = 0;
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(173, 47);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 1;
            this.button1.Text = "显示主详细窗体";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(24, 15);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(53, 12);
            this.label1.TabIndex = 2;
            this.label1.Text = "测试内容";
            // 
            // MainForm
            // 
            this.ClientSize = new System.Drawing.Size(292, 82);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.textBox1);
            this.Name = "MainForm";
            this.Text = "主窗体";
            this.Load += new System.EventHandler(this.MainForm_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            //设置绑定
            textBox1.DataBindings.Add("Text", StaticClass.ModuleClass, "Test", false, DataSourceUpdateMode.OnPropertyChanged);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            new DetailForm().Show();
        }
    }
}

DetailForm.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public class DetailForm:Form
    {
        private Label label1;
        private TextBox textBox1;

        public DetailForm()
        {
            InitializeComponent();
        }
    
        private void InitializeComponent()
        {
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(124, 12);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(156, 21);
            this.textBox1.TabIndex = 0;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(27, 15);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(53, 12);
            this.label1.TabIndex = 1;
            this.label1.Text = "测试内容";
            // 
            // DetailForm
            // 
            this.ClientSize = new System.Drawing.Size(292, 72);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.textBox1);
            this.Name = "DetailForm";
            this.Text = "详细窗口";
            this.Load += new System.EventHandler(this.DetailForm_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void DetailForm_Load(object sender, EventArgs e)
        {
            //设置绑定
            textBox1.DataBindings.Add("Text", StaticClass.ModuleClass, "Test", false, DataSourceUpdateMode.OnPropertyChanged);
        }
    }
}

ModuleClass.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace WindowsApplication1
{
    /**//// <summary>
    /// 数据实体类
    /// </summary>
    public class ModuleClass
    {
        private string test;

        /**//// <summary>
        /// 获取或设置测试属性
        /// </summary>
        public string Test
        {
            get { return test; }
            set { test = value; }
        }
    }
}

StaticClass.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace WindowsApplication1
{
    /**//// <summary>
    /// 提供全局访问变量
    /// </summary>
    public class StaticClass
    {
        private static ModuleClass module = new ModuleClass();

        /**//// <summary>
        /// 获取模型对象
        /// </summary>
        public static ModuleClass ModuleClass
        {
            get { return module; }
        }
    }
}

Program.cs

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace WindowsApplication1
{
    static class Program
    {
        /**//// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }
    }
}

转载于:https://www.cnblogs.com/icoolno1/archive/2006/10/23/537540.html

使用数据绑定实现多窗口间的数据同步相关推荐

  1. 初识Dockerfile与实现容器间的数据同步

    初识Dockerfile与实现容器间的数据同步 1.初识Dockerfile 2.实现容器间的数据同步 1.初识Dockerfile Dockerfile简单来说就是用来构建docker镜像的构建文件 ...

  2. 网络云存储技术Windows server 2012 (项目十五 存储服务间的数据同步)

    网络云存储技术Windows server 2012 (项目十五 存储服务间的数据同步) 目录 前言 一.项目背景 二. 项目实训题 前言 网络存储技术,是以互联网为载体实现数据的传输与存储,它采用面 ...

  3. 多台个人电脑间的数据同步

    相信很多人都在同时使用多台计算机:家里,办公室,或者其它秘密地方.当然就算现在没有多台电脑,将来也会有的. 多台电脑对应多个硬盘,也对应着多个文件夹.如何进行数据同步是很多人头痛的问题,完全靠 U 盘 ...

  4. 通过BizTalk WCF适配器实现异构数据库/系统间的数据同步

    概述 数据库与数据库之间的同步,是EAI(企业应用整合)非常普遍的需求,BizTalk作为企业ESB平台,以SOA的架构方式来实现异构系统之间的整合,今天我们就来介绍如何使用BizTalk的适配器来实 ...

  5. Cocos2dx中lua实现与java交互(异步线程间的数据同步)

    语言环境 Cocos2dx 3.6 lua 5.1 java 1.8.0_144 本节问题: lua 通过 luaj与java交互,在java中,如何回调lua?若要处理的事件代码必须在多线程中执行, ...

  6. 实现linux作为server时与windows间的数据同步

    1.准备机器,此时使用linux作为server  server---10.0.0.13    (linux)  client---172.168.32.9 (windows)    2.安装与配置l ...

  7. 05丨数据同步:主从库如何实现数据一致

    文章目录 1. 主从库数据同步介绍 2. 主从库间如何进行第一次同步 3.主从级联模式分担全量复制时的主库压力 4.主从库间网络断了怎么办? 1. 主从库数据同步介绍   Redis 具有高可靠性有两 ...

  8. 华为云严选上新啦!高效准确的数据同步方案来了

    摘要:英方软件i2Stream产品服务已上架华为云严选商城啦! 近期,上海英方软件股份有限公司(简称"英方软件")宣布加入华为云沃土云创计划,同时基于i2Stream(数据流复制管 ...

  9. 二、Eureka之server端集群节点发现,数据同步

    一.前言 Eureka服务端封装了一个集群节点管理的类名称为PeerEurekaNodes 通过名称翻译出来为对等的Eureka节点集合,可以看出这个类是对eureka服务端集群节点抽象,下面通过源码 ...

  10. 异地多活数据同步平台

    摘自<大型企业微服务架构实践与运营> 薛浩 编著 异地多活数据同步平台 1. 异地多活架构 接入层应用可通过同步调用或异步消息实现相互的调用.通过相关的服务注册和发现机制保障寻址.路由.熔 ...

最新文章

  1. SAP MM 明明有维护源清单,还是不能下PO?
  2. 报告|机器人行业深度报告:机器人产业价值与回报相关度分析
  3. F5负载均衡配置手册-实操后的
  4. LinkedHashMap源码分析
  5. ultraedit java_UltraEdit配置java环境
  6. .Net Discovery系列之十二-深入理解平台机制与性能影响(下)
  7. centos 8 安装使用配置
  8. wget下载一个目录下的文件
  9. python只能对列表进行切片_Python中的列表
  10. oracle诊断日志,oracle日常诊断语句
  11. 联想成为中国女排主赞助商,却被自媒体攻击?网友:还好没赞助国足
  12. CCNP实验4-2:配置多区域和NBMA OSPF
  13. 一起学习MVC(4)-entity SQL语句
  14. macBook Air出现部分乱码问题解决(浏览器、appstore乱码)
  15. 微信公众平台php开发包
  16. android数据格式化,手机格式化了?教你找回安卓手机误删数据
  17. ubuntu 19.04下交叉编译64位vlc 3.0.8
  18. MSDC 4.3 接口规范(4)
  19. 如何在R中画出高效美观的相关性分析图
  20. PTA题目 查询水果价格

热门文章

  1. mac查看进程 总是忘记
  2. 紧急!Log4j2 再再爆雷:刚升级,又连爆 “核弹级” 远程数据泄露 ! v2.17.0 横空出世。。。...
  3. SpringBoot四大核心组件,你了解多少
  4. 想接私活收入翻倍,建议根据这几个开源SpringBoot项目(含小程序)改改~
  5. 怎么用追 MM 来理解 23 种设计模式?
  6. 这个教人写出烂代码的项目在 GitHub 上火了...
  7. 一位程序员的十年工作总结,值得每位互联网人看
  8. BAT 解密:一张图概括互联网公司的标准技术架构
  9. hao123谢幕,那是80后青春的记忆
  10. 【限时免费】云计算时代的安全和智能运维(11月18日周六|广州)