zoukankan      html  css  js  c++  java
  • windows form参数传递过程

     1 三、windows form参数传递过程 
     2 在Windows 程序设计中参数的传递,同样也是非常的重要的。 
     3 这里主要是通过带有参数的构造函数来实现的, 
     4 
     5 说明:Form1为主窗体,包含控件:文本框textBoxFrm1,多选框checkBoxFrm1和按钮buttonEdit;  
     6 Form2为子窗体,包含控件:文本框textBoxFrm2,多选框checkBoxFrm2和按钮buttonOK,buttonCancel。 
     7 当我们新建一个窗体的时候,设计器会生成默认的构造函数:  
     8      public Form2() 
     9               { 
    10                    InitializeComponent(); 
    11             } 
    12 它不带参数,既然我们要把Form1中的一些数据传到Form2中去,为什么不在Form2的构造函数里做文章呢? 
    13 假设我们要实现使Form2中的文本框显示Form1里textBoxFrm1的值,修改子窗体的构造函数:  
    14 public Form2(string text)          
    15               { 
    16                    InitializeComponent(); 
    17                    this.textBoxFrm2.Text = text;  
    18             } 增加Form1中的修改按钮点击事件,处理函数如下:  
    19      private void buttonEdit_Click(object sender, System.EventArgs e) 
    20               { 
    21                    Form2 formChild = new Form2(this.textBoxFrm1.Text); 
    22                    formChild.Show(); 
    23               } 
    24 
    25 我们把this.textBoxFrm1.Text作为参数传到子窗体构造函数,以非模式方式打开,这样打开的formChild的文本框就显示了”主窗体”文本,是不是很简单,接下来我们传一个boolean数据给子窗体。 
    26      Public Form2(string text,bool checkedValue) 
    27          { 
    28               InitializeComponent(); 
    29               this.textBoxFrm2.Text = text; 
    30               this.checkBoxFrm2.Checked = checkedValue; 
    31          } 
    32 
    33 private void buttonEdit_Click(object sender, System.EventArgs e) 
    34          { 
    35               Form2 formChild = new Form2(this.textBoxFrm1.Text,this.checkBoxFrm1.Checked); 
    36               formChild.Show(); 
  • 相关阅读:
    jmeter 工具学习 未完待续
    测试学习
    JavaScript
    新概念第1册
    day08
    LeetCode OJ:Invert Binary Tree(反转二叉树)
    LeetCode OJ:Lowest Common Ancestor of a Binary Search Tree(最浅的公共祖先)
    LeetCode OJ:Maximum Depth of Binary Tree(二叉树最大深度)
    LeetCode OJ:Path Sum(路径之和)
    LeetCode OJ:Symmetric Tree(对称的树)
  • 原文地址:https://www.cnblogs.com/yuhuameng/p/3662010.html
Copyright © 2011-2022 走看看