C#成神之路 <22> 窗体跳转以及数据传递

来源:互联网 发布:上海房价 知乎 编辑:程序博客网 时间:2024/05/17 23:49

这里的知识内容参考网络层面较多:
设计窗体数据传递必然少不了委托和事件,我参考的学习资料:
委托和事件的基础解释

一位大手的白话解释委托和事件

对窗体数据传递方法的详细介绍

感谢上面诸多大手的奉献。

下面列出本人关于窗体之间跳转和数据传递所编写的简单代码:

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;using System.Media;namespace 窗体数据传递{    public delegate void MyInvoke(string Item1);    public partial class frmMain : Form    {        public frmMain()        {            InitializeComponent();        }        public static void Main()        {            frmMain main = new frmMain();            Application.Run(main);        }        private void btnClose_Click(object sender, EventArgs e)        {            Close();        }        private void btnGo_Click(object sender, EventArgs e)        {            Form1 sonForm1 = new Form1(this, new MyInvoke(UpdatetxtOutput));            sonForm1.Show();            this.Hide();        }        private void UpdatetxtOutput(string Item1)        {            txtOutput.Text = Item1;        }        private void frmMain_Load(object sender, EventArgs e)        {            string k = @"F:\学习文件\C++练习\窗体数据传递\bin\Ramin Djawadi - Main Titles 音频已提取.wav";            SoundPlayer sp = new SoundPlayer(k);            sp.PlayLooping();            ToolTip a = new ToolTip();            a.AutoPopDelay=200;            a.SetToolTip(txtOutput,"my output");        }        private void txtOutput_TextChanged(object sender, EventArgs e)        {        }        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)        {        }        private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)        {            cmbIn.Items.Add(clbSelect.CheckedItems);        }    }}
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 窗体数据传递{    public partial class Form1 : Form    {        private MyInvoke mi = null;        Form f1 = new Form();        public Form1(Form f,MyInvoke myInvoke)        {            this.mi = myInvoke;            InitializeComponent();            f1 = f;        }        private void btnClose_Click(object sender, EventArgs e)        {            this.Close();            f1.Show();        }        private void btnIn_Click(object sender, EventArgs e)        {            this.mi(this.textBox1.Text);        }    }}
0 0
原创粉丝点击