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开发时简单的界面传值与简单操作. 涉及两个界面:一 ...
随机推荐
- pl/sql的to_char和to_date
今天同事让笔者将sql查询出来的时间转换为指定格式的字符串,笔者当时懵逼了,印象中记得有处理过,但就是一时想不起来了,等处理了这个问题后,笔者觉得有必要记录一下,毕竟不知道这个是很掉面子的事不是?好了 ...
- Wcf调用方式
C#动态调用WCF接口,两种方式任你选. 写在前面 接触WCF还是它在最初诞生之处,一个分布式应用的巨作. 从开始接触到现在断断续续,真正使用的项目少之又少,更谈不上深入WCF内部实现机制和原理去 ...
- 【转】Spring事务介绍
1. 事务的特性:ACID 原子性(Atomicity):事务是一个原子操作,由一系列动作组成.事务的原子性确保动作要么全部完成,要么完全不起作用. 一致性(Consistency):一旦事务完成(不 ...
- 由等概率生成的0和1构建rand()函数
问题:有函数rand01()能够等概率的生成0和1,用rand01生成rand(n),使其能够等概率的生成0-n-1的整数. java代码: public int rand(int n){ while ...
- Codeforces 1109D (树的计数问题)
思路看这篇博客就行了:https://www.cnblogs.com/zhouzhendong/p/CF1109D.html, 讲的很好 今天学到了prufer编码,这是解决树上计数问题的一大利器,博 ...
- 微信小程序怎么获取用户输入
能够获取用户输入的组件,需要使用组件的属性bindchange将用户的输入内容同步到 AppService. <input id="myInput" bindchange=& ...
- 686. Repeated String Match 字符串重复后的子字符串查找
[抄题]: Given two strings A and B, find the minimum number of times A has to be repeated such that B i ...
- c语言学习笔记 break语句
比如 for() { for() { break; } } 那个break语句只是跳出它所在的那个for循环,不会把最外面的for循环都跳出去.
- PyV8在服务端运行自动崩溃问题
近来想在服务端架设WSGI + PyV8去自动解析JavaScript代码,然后返回解析后的数据给客户端.但是发现,在nginx配置后,客户端一请求,服务端的python脚本自动崩溃. 见代码: de ...
- 用js获取cookie
//获取cookiefunction cookie_email(cookie_name){ var cookiestr = document.cookie; if (cookiestr.length ...