zoukankan      html  css  js  c++  java
  • WinForm窗体间传值

    Form1——主窗体:

    namespace FirstDlg
    {
        public partial class Form1 : Form
        {
            private Form2 f;
            public Form1()
            {
                InitializeComponent();
            }
            public string TextStored
            {
                get { return tbTest.Text; }
                set { tbTest.Text = value; }
            }
            private void button1_Click(object sender, EventArgs e)
            {
                tbTest.Text = f.TextStored;//属性传值
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                f = new Form2();
                f.Show();
            }
        }
    }

    Form2——对话框窗体:

    namespace FirstDlg
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
            public string TextStored
            {
                get { return tbTest.Text; }
                set { tbTest.Text = value; }
            }
            private void btnOK_Click(object sender, EventArgs e)
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }

            private void btnCancel_Click(object sender, EventArgs e)
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                foreach (Form form in Application.OpenForms)//搜索窗体名称
                {
                    if (form.Name == "Form1")
                    {
                        Form1 f = (Form1)form;
                        tbTest.Text = f.TextStored;
                    }
                }
            }
        }
    }

  • 相关阅读:
    第四次上课 PPT作业
    大道至简 读后感④
    第三次上课 PPT 课后测试
    大道至简 读后感③
    Java 02 课后作业
    Java 多个数字相加算法
    大道至简 读后感②
    wpf控件
    一个简单的prism mef例子
    c#弱事件(weak event)
  • 原文地址:https://www.cnblogs.com/pyt5208/p/1336811.html
Copyright © 2011-2022 走看看