C# 遍历界面指定控件

    xiaoxiao2021-12-02  28

      查找界面上所有的TextBox控件,并给他赋初始值为 "aaa" 

    public void SetText(Control cc) { foreach (System.Windows.Forms.Control control in cc.Controls) { if (control is System.Windows.Forms.TextBox) { System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control; tb.Text = "aaa"; } if (control.Controls.Count >0) { SetText(control); } } }

    调用方法:

    private void Form2_Load(object sender, EventArgs e) { SetText(this); }

    效果图:

    转载请注明原文地址: https://ju.6miu.com/read-679806.html

    最新回复(0)