C# winform间窗体传值简单Demo
form1是用来接收值的

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 DelegateEventDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Form2 f2 = new Form2();
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "接收值";
f2.DelegateEvent += new Form2.DelegateMessage(GetText);
}
private void GetText(string msg)
{
this.textBox1.Text = msg;
} private void button1_Click(object sender, EventArgs e)
{
f2.Show();
}
}
}
Form1代码
form2是发送值的

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 DelegateEventDemo
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} public delegate void DelegateMessage(string txt);//声明一个委托
public event DelegateMessage DelegateEvent;//声明委事件 private void Form2_Load(object sender, EventArgs e)
{
this.Text = "传值窗体";
} private void button1_Click(object sender, EventArgs e)
{
DelegateEvent(this.textBox1.Text);
}
}
}
From2代码
1.委托是把方法当做参数一样使用
a)委托(int a,int b)
方法(int a,int b)
{
return a+b;
}
委托 委托对象=new 委托(方法名);
int sum=委托对象(5,3);
结果 sum=8;
C# winform间窗体传值简单Demo的更多相关文章
- CS中委托与事件的使用-以Winform中跨窗体传值为例
场景 委托(Delegate) 委托是对存有某个方法的引用的一种引用类型变量. 委托特别用于实现事件和回调方法. 声明委托 public delegate int MyDelegate (string ...
- WinForm跨窗体传值
1.另一窗体建公共变量listdataRow public List<DataGridViewRow> listdataRow = new List<DataGridViewRow& ...
- Winform 委托窗体传值
有窗体Form1和窗体Form2,单击Form1按钮弹出Form2,单击Form2吧Form2的textBox控件文本传给Form1的label控件. 窗体1里: 实例化Form2,注册Form2的事 ...
- C#winform跨窗体传值和调用事件的办法
有三个窗体,分别是Main主窗体,Form1窗体1,From2窗体2,其中Main是主窗体,Form1窗体1是一个消息通知窗体,Form2窗体2主窗体的一个子窗体,程序启动时,消息框窗体1弹出,通过消 ...
- C#学习笔记(31)——委托窗体传值
说明(2017-11-23 19:31:53): 1. 关于委托和窗体传值,一下午在网上查阅了大量资料,基本就是CSDN的论坛和博客园的文章,大家都在举例子,烧水.鸿门宴,看评论说还看到过沙漠足球的, ...
- WinForm窗体间如何传值
窗体间传递数据,无论是父窗体操作子窗体,还是子窗体操作符窗体,有以下几种方式: 公共静态变量: 使用共有属性: 使用委托与事件: 通过构造函数把主窗体传递到从窗体中: 一.通过静态变量 特点:传值是双 ...
- WinForm窗体间如何传值的几种方法
(转) 窗体间传递数据,无论是父窗体操作子窗体,还是子窗体操作符窗体,有以下几种方式: 公共静态变量: 使用共有属性: 使用委托与事件: 通过构造函数把主窗体传递到从窗体中: 一.通过静态变量 特点: ...
- c# winform 窗体间的传值
1.父窗体传值给子窗体: 1) 父窗体: FrmXX frm = ,); frm.Owner = this; frm.ShowDialog(); 子窗体: ; public FrmXX(int ty, ...
- .NET开发之窗体间的传值转化操作
DOTNET开发之窗体间的传值转化操作 好想把自己最近学到的知识写下来和各位朋友分享,也希望得到大神的指点.今天终于知道自己要写点什么,就是关于WPF开发时简单的界面传值与简单操作. 涉及两个界面:一 ...
随机推荐
- 201671010140. 2016-2017-2 《Java程序设计》java学习第三周
java学习第三周 不知不觉,学习java已经是第三周了,不同于初见时的无措,慌张,在接触一段时日后,渐渐熟悉了一些,了解到了它的便利之处,也体会到了它的一些难点,本周主攻第四章,< ...
- 设置窗口的z-order总是在最底部
想让窗口置顶,很简单,只需要在SetWindowPos中指定 HWND_TOPMOST就OK了, 但是如果想要窗口始终位于最底端,Windows却没有提供接口. 不过呢,Windows提供了一个消息W ...
- 50. Pow(x, n) 幂次方
[抄题]: mplement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, ...
- nginx配置跨域访问
前端要在本地测试ajax接口,无法跨域访问,所以在测试环境的nginx配置了跨域支持,方法如下: 在nginx.conf文件, http块下配置 42 #support cross domain ac ...
- 数字图像处理实验(17):PROJECT 06-04,Color Image Segmentation 标签: 图像处理MATLAB 2017-05-27 21:13
实验报告: Objective: Color image segmentation is a big issue in image processing. This students need to ...
- R语言安装包,切换镜像
source("http://bioconductor.org/biocLite.R") options(BioC_mirror="http://mirrors.ustc ...
- Hibernate-Criteria
Hibernate Criteria简介 一.Criteria接口的用途: 设计上可以灵活的根据criteria的特点进行查询条件的组装. CriteriaSpecification 接口是 Crit ...
- PHP中 null ,false , 区别
先来测试一下吧: if(0 ==''){ echo '<br/>在PHP中0 ==\'\'' ; } if(0 !==''){ echo '<br/>在PHP中0 !==\'\ ...
- Laravel 的 make:auth Artisan 命令到底生成了哪些文件?
众所周知,在 Laravel 中执行 $ php artisan make:auth $ php artisan migrate 命令后,我们就能拥有一个完整的登录.注册认证系统,这为开发带来极大的便 ...
- (转)Asp.Net底层原理(三、Asp.Net请求响应过程)
原文地址:http://www.cnblogs.com/liuhf939/archive/2013/09/16/3324753.html 在之前,我们写了自己的Asp.Net框架,对整个流程有了一个大 ...