winform程序两个窗体间同步数据(三):建立父窗口与子窗口的父子关系(不使用线程)
来源:互联网 发布:java初级中级高级区别 编辑:程序博客网 时间:2024/06/08 02:16
一 问题:
1 可不可以不使用线程?
可以。需要建立父窗口和子窗口之间的父子关系。
2 如何建立父子关系?
在子窗体中增加一个类型为父窗口的属性(即ChildFrm类中设置 public ParentFrm parentFrm{get;set;}属性)。
二 显示效果
三 代码
1 入口程序
using System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms;namespace WindowsFormsApplication1{ static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); ParentFrm parentFrm = new ParentFrm(); Application.Run(parentFrm);//启动父窗体 } }}
2父窗体
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplication1{ public partial class ParentFrm : Form { public ParentFrm() { InitializeComponent(); } public TextBox GetTbParent() { return this.TbParent;//TbParent 是私有的对象 ,所以要有公有的方法获取TbParent对象 } private void button1_Click(object sender, EventArgs e)//点击事件 { ChildFrm childFrm = new ChildFrm(); childFrm.parentFrm = this; //建立父子关系 childFrm.Show();//显示子窗体 } }}
3 子窗体
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplication1{ public partial class ChildFrm : Form { public ParentFrm parentFrm{get;set;} public ChildFrm() { InitializeComponent(); } private void TbChild_TextChanged(object sender, EventArgs e) { parentFrm.GetTbParent().Text = this.TbChild.Text;//将用户输入到子窗体TEXTBOX控件中的内容放入到父窗体的TEXTBOX控件中 } }}
0 0
- winform程序两个窗体间同步数据(三):建立父窗口与子窗口的父子关系(不使用线程)
- winform程序三个窗体间同步数据(四):建立兄弟关系(不适用线程)
- winform程序两个窗体间同步数据(二): 子窗体和线程实现
- winform程序两个窗体间同步数据(一): 静态变量和线程实现
- JS 子窗口与父窗口间的数据传递
- JS 子窗口与父窗口间的数据传递
- 父窗口与子窗口的层次关系
- WPF:父窗口与子窗口的层次关系
- Qt中父窗口与子窗口之间的关系
- 父窗口与子窗口的层次关系
- WPF:父窗口与子窗口的层次关系
- 父窗口与子窗口的层次关系
- Qt中父窗口与子窗口之间的关系
- 父窗口与子窗口的层次关系
- 线程面试题之三:父子线程和子线程之间的同步与互斥
- C# winform TabPage两个存在关联关系的窗体数据不刷新问题
- 父窗口与子窗口的数据传递问题
- [VB.NET]父窗口怎么向子窗口传值?(刚开始做winform的程序)
- PHP获取文件扩展名的4种方法
- ==运算符与equals方法
- Java笔记->LinkedList基本用法
- php获取文件名称和扩展名
- react-native入门之快速入门---返回键实现
- winform程序两个窗体间同步数据(三):建立父窗口与子窗口的父子关系(不使用线程)
- Java学习笔记-数组的三种初始化方式
- 海康相机RTSP连接代码分析
- IOS设置窗口方向
- SQL Server 2016 的JSON功能
- Programming Collective Intelligence 学习笔记第一章
- react native 一次内存泄漏分析
- 第三方免费加固横向对比(转)
- 关于camera be called after release()的异常