• 窗体之间传值、父窗体控制子窗体


    如何在窗体之间传值

      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 = "我被父窗体修改了文字";
  • 相关阅读:
    字典列表元组的推导式使用方法
    算法之排序
    闭包与装饰器
    循环(打印一些小东西)
    iOS内存小知识
    NSset
    字典
    NSNumber
    NSString
    NSArray
  • 原文地址:https://www.cnblogs.com/hoosway/p/3723239.html
Copyright © 2020-2023  润新知