将控件添加到面板,控件不再显示 C#

本文关键字:控件 不再 显示 添加 | 更新日期: 2023-09-27 18:36:31

我有一个文本框(textBox1)和面板(Panel1)我有这样的代码

Panel1.Controls.Add(textBox1)

所以当我运行它时,我再也看不到文本框了,如果我这样做,我可以看到文本框

textBox1.Location  = Panel1.Location

谁能告诉我有什么问题?

将控件添加到面板,控件不再显示 C#

当文本框(或任何控件)是面板的一部分时,面板的左上角是 point(0.0);

因此,当文本框 1.位置 = 面板 1.位置时,文本框可能会在面板中消失。

试试这样的东西/

        // 
        // panel1
        // 
        this.panel1.Controls.Add(this.textBox1);
        this.panel1.Location = new System.Drawing.Point(59, 27);
        this.panel1.Name = "panel1";
        this.panel1.Size = new System.Drawing.Size(193, 176);
        this.panel1.TabIndex = 1;
        // 
        // textBox1
        // 
        this.textBox1.Location = new System.Drawing.Point(0, 0);
        this.textBox1.Name = "textBox1";
        this.textBox1.Size = new System.Drawing.Size(100, 20);
        this.textBox1.TabIndex = 0;
我相信

您无法看到文本框的原因与面板的属性有关。尝试将"自动大小"属性设置为"true",将"自动调整大小模式"属性设置为"GrowAndShrink"。