zoukankan      html  css  js  c++  java
  • WinForm 参数传递(转载)

     

    父窗体给子窗体传参

    子窗体代码:
    //添加构造函数
    public Form2(string param)
    {
         InitializeComponent();
           textBox1.Text 
    = param;
    }


    父窗体代码:
    private void button2_Click(object sender, EventArgs e)
    {
          Form2 f 
    = new Form2(textBox1.Text);
           f.StartPosition 
    = FormStartPosition.CenterParent;
           f.ShowDialog();
    }


    子窗体给父窗体传参

    子窗体代码:
    //添加属性
            public string Parameter1
            
    {
                
    get return textBox1.Text; }
            }


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

    父窗体代码:
            
    private void button1_Click(object sender, EventArgs e)
            
    {
                Form2 f 
    = new Form2(); //Form2为子窗体名称
                f.StartPosition = FormStartPosition.CenterParent;
                
    if (f.ShowDialog(this== DialogResult.OK)
                
    {
                    button1.Text 
    = f.Parameter1;
                }

            }

  • 相关阅读:
    LeetCode -- Rectangle Area
    【转】VS常用快捷键
    C++中include<> 与 include" " 的区别
    浅析_tmain() 与 main() 函数的区别
    VS2013下配置OpenCV 3.0.0 &&& VS2013下配置Opencv2.4.9
    LeetCode -- Valid Parenthese
    杂想 · 警醒
    LeetCode -- Length of Last Word
    LeetCode -- Valid Sudoku
    LeetCode -- Binary Tree Level Order Traversal II
  • 原文地址:https://www.cnblogs.com/zpq521/p/1240219.html
Copyright © 2011-2022 走看看