【C#】winform通过事件跨窗口传值
|
admin
2026年1月19日 20:10
本文热度 91
|
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 ImainformTest{
public partial class Form1 : Form { public childForm form1; private void Form1_Load(object sender, EventArgs e) { form1 = new childForm(); form1.sendForm += show; }
public Form1() { InitializeComponent(); }
private void btnSend_Click(object sender, EventArgs e) {
form1.Show(); form1.receiveFromForm(txtData.Text); } public void show(string str) { txtRce.Text = str; }
}}
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.Web;using System.Windows.Forms;
namespace ImainformTest{
public partial class childForm : Form {
public event Action<string> sendForm; public childForm() { InitializeComponent(); } public void receiveFromForm(string str) { txtReceive.Text = str; } private void btnSend_Click(object sender, EventArgs e) { sendForm.Invoke(txtSend.Text); } }}
阅读原文:原文链接
该文章在 2026/1/20 10:28:56 编辑过