C#中用到的窗体传值技术

C#中用到的窗体传值技术
C#中用到的窗体传值技术

具体的传值示例代码:

Form3的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace winForm窗体间相互传值
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }


        public string TextBox1Value
        {
            set { txtForm3.Text = value; }
            get { return txtForm3.Text; }
        
        }
        private void Form3_Load(object sender, EventArgs e)
        {

        }

        private void btnForm3_Click(object sender, EventArgs e)
        {
            Form4 f4 = new Form4();
            f4.U4 = txtForm3.Text.Trim();
            f4.Show(this);
        }
    }
}

Form4 的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace winForm窗体间相互传值
{
    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();
        }


        public string U4 { get; set; }
        private void button1_Click(object sender, EventArgs e)
        {
            Form3 f3 = (Form3)this.Owner;
            f3.TextBox1Value = txtForm4.Text;
            //this.Close();
        }

        private void Form4_Load(object sender, EventArgs e)
        {
            txtForm4.Text = U4;


        }
    }
}