zoukankan      html  css  js  c++  java
  • 窗体之间传值、父窗体控制子窗体

    如何在窗体之间传值

      1.可以使用构造静态类作为“中间件”

    static class Record
    {
            //静态类里存放需要共享的值
    }

      2.可以自定义一个窗体构造函数,达到传值的目的

    //定义要传递的值
    private int id;
    private string name;
    
    //自己写一个构造函数的重载
    public frmNewForm(int id, string name)
    {
        InitializeComponent();
        this.id = id;
        this.name = name;
    }
    
    //然后在其他地方使用
    frmNewForm fm = new frmNewForm(10, "王小鸭");
    fm.Show();

    如何用父窗体控制子窗体的控件

    打开 frmNewForm.Descginer.cs
    修改 public System.Windows.Forms.Button button1;
           为
           private System.Windows.Forms.Button button1;
    
    
    然后在父窗体事件中写:
        frmNewForm fm = new frmNewForm();
        fm.Show();
        fm.Button1.Text = "我被父窗体修改了文字";
  • 相关阅读:
    Idea中SpringBoot热部署搭建
    Redis 集群搭建
    centos7 vsftp搭建
    Centos 7 安装jdk
    Centos7 安装nginx
    Xshell 连接Linux
    python 的mysql 操作
    NIO/BIO
    java基础-3
    java基础-2
  • 原文地址:https://www.cnblogs.com/hoosway/p/3723239.html
Copyright © 2011-2022 走看看