c# 使用委托子窗体改变父窗体控件
2024-09-08 11:44:19
首先创建两个窗体,在窗体1和窗体2放上对应的控件
在窗体1的代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 委托改变控件值
{
public delegate void MyDel();
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
public static MyDel myDel;//定义一个委托类型的变量
public static string str;//定义一个静态类型的字段
public Form1()
{
InitializeComponent();
myDel = new MyDel(Change);
}
/// <summary>
/// 更改值
/// </summary>
public void Change()
{
label1.Text = str;
}
private void button1_Click(object sender, EventArgs e)
{
Form2 fom = new Form2();
fom.ShowDialog();
}
}
}
窗体2的代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 委托改变控件值
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//把值传递到父窗体
Form1.str = textEdit1.Text;
//调用委托
Form1.myDel();
}
}
}
窗体1的lab根据窗体而的文本框而改变
demo下载链接https://download.csdn.net/download/qq_38977099/10872406
大家如果有问题可以
Console.WriteLine(”加群“+"537905238");
最新文章
- 【poj2122】 Optimal Milking
- 怎样让Oracle支持中文? 语言_地域.字符集
- centos 7 升级后yum install出现Exiting on user cancel
- JavaWEB前端向服务器端发送对象
- Qt Focus事件,FocusInEvent()与FocusOutEvent()
- nohup不输出日志信息的方法,及linux重定向学习
- IE和火狐 差异
- Bezier曲线的原理 及 二次Bezier曲线的实现
- JS链表
- python css概述
- java,while循环的使用,接收用户的输入,进行不同的操作!
- 数据结构基础——结构体struct及类型别名typedef的使用
- 队列(FIFO)—循环队列、队列的链式存储
- django中url路由配置及渲染方式
- Flask web开发之路十三
- Unescaped left brace in regex is illegal here in regex; marked by <;-- HERE in m/\${ <;-- HERE ([^ \t=:+{}]+)}/ at xxxx/usr/bin/automake line 3939.
- Machine Learning Library (MLlib) Guide, BOOKS
- Linux系统性能监控之6个vmstat和6个iostat命令
- ICE简介及C++程序例子(转)
- Northwestern European Regional Contest 2017-I题- Installing Apps题解
热门文章
- 【读书笔记】C#高级编程 第十五章 反射
- IDEA远程部署项目到Docker
- 配置logstash消费kafka多个topic,分别生成索引
- 11. Fluentd部署:性能优化
- 使用 HammerDB 对 Citus 和 Postgres 进行 Benchmark,每分钟200万新订单处理测试(官方博客)
- PHP全栈开发(六):PHP与HTML页面交互
- HDU3506 Monkey Party (区间DP)
- AVX图像算法优化系列二: 使用AVX2指令集加速查表算法。
- Redis高可用之主从复制原理演进分析
- Audacity开源音频处理软件使用入门