• 窗体相互传值


    属性法:

    Form2:

    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 窗体属性传值
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
            private string _str;
            public string str
            {
                set { _str = value; }
                get { return _str; }

            }
            private void Form2_Load(object sender, EventArgs e)
            {
                textBox1.Text = _str;
            }
        }
    }

    Form1

    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 窗体属性传值
    {
        public partial class Form1 : Form
        {
            public  Form1()
            {
                InitializeComponent();
            }
          
            private void button1_Click(object sender, EventArgs e)
            {
                Form2 f2 = new Form2();
                f2.str = textBox1.Text;
                f2.ShowDialog();
               
            }
        }
    }

     构造函数法:

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

    namespace 窗体间通迅
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                Form2 frm = new Form2(this.textBox1);
                frm.Show();

            }
        }
    }

    ///Form2.cs  the form contains a textbox and a button
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace 窗体间通迅
    {
        public partial class Form2 : Form
        {
            private delegate void dg();

            /// <summary>
            /// 让其与窗体1的TextBox1同一个引用。
            /// </summary>
            private TextBox textBox12;

            public Form2()
            {
                InitializeComponent();
            }

            public Form2(TextBox txtBox)
            {
                InitializeComponent();
                textBox1.Text = txtBox.Text; ;
                this.textBox12 = txtBox;
               
            }

            private void button1_Click(object sender, EventArgs e)
            {
                textBox12 .Text  = textBox1.Text;
                this.Close();
               
            }
        }
    }

    构造函数传值

    Form2

    public Picture(string f,string picfile,string note)
            {
                InitializeComponent();
                this._f = f;
                this._picfile=picfile;
                this._note = note;
            }
            private string _f;
            private string _picfile;
            private string _note;

    Form2

                int foodid = int.Parse(dataGridView1.Rows[index].Cells["foodid"].Value.ToString());
                string picfile = dataGridView1.Rows[index].Cells["picturefile"].Value.ToString();
                string note = dataGridView1.Rows[index].Cells["note"].Value.ToString();
                Picture f = new Picture(foodid.ToString(),picfile,note);
                f.Show();

  • 相关阅读:
    红黑树插入与删除完整代码(dart语言实现)
    红黑树的删除详解与思路分析——不同于教科书上的算法(dart语言实现)
    数据结构与算法之二叉树 ——in dart
    数据结构与算法之排序(4)希尔排序 ——in dart
    数据结构与算法之链表(LinkedList)——简单实现
    数据结构与算法之Stack(栈)——重新实现
    数据结构与算法之Stack(栈)的应用——用stack实现一个计算器-/bin/calc.dart
    数据结构与算法之Stack(栈)的应用——用stack实现一个计算器——in dart
    数据结构与算法之Stack(栈)的应用——in dart
    数据结构与算法之Stack(栈)——in dart
  • 原文地址:https://www.cnblogs.com/yuerdongni/p/2644648.html
Copyright © 2020-2023  润新知