首先创建两个窗体,在窗体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");

最新文章

  1. 【poj2122】 Optimal Milking
  2. 怎样让Oracle支持中文? 语言_地域.字符集
  3. centos 7 升级后yum install出现Exiting on user cancel
  4. JavaWEB前端向服务器端发送对象
  5. Qt Focus事件,FocusInEvent()与FocusOutEvent()
  6. nohup不输出日志信息的方法,及linux重定向学习
  7. IE和火狐 差异
  8. Bezier曲线的原理 及 二次Bezier曲线的实现
  9. JS链表
  10. python css概述
  11. java,while循环的使用,接收用户的输入,进行不同的操作!
  12. 数据结构基础——结构体struct及类型别名typedef的使用
  13. 队列(FIFO)—循环队列、队列的链式存储
  14. django中url路由配置及渲染方式
  15. Flask web开发之路十三
  16. Unescaped left brace in regex is illegal here in regex; marked by &lt;-- HERE in m/\${ &lt;-- HERE ([^ \t=:+{}]+)}/ at xxxx/usr/bin/automake line 3939.
  17. Machine Learning Library (MLlib) Guide, BOOKS
  18. Linux系统性能监控之6个vmstat和6个iostat命令
  19. ICE简介及C++程序例子(转)
  20. Northwestern European Regional Contest 2017-I题- Installing Apps题解

热门文章

  1. 【读书笔记】C#高级编程 第十五章 反射
  2. IDEA远程部署项目到Docker
  3. 配置logstash消费kafka多个topic,分别生成索引
  4. 11. Fluentd部署:性能优化
  5. 使用 HammerDB 对 Citus 和 Postgres 进行 Benchmark,每分钟200万新订单处理测试(官方博客)
  6. PHP全栈开发(六):PHP与HTML页面交互
  7. HDU3506 Monkey Party (区间DP)
  8. AVX图像算法优化系列二: 使用AVX2指令集加速查表算法。
  9. Redis高可用之主从复制原理演进分析
  10. Audacity开源音频处理软件使用入门