简体   繁体   English

向面板添加控件,并且控件不再显示c#

[英]add control to Panel and control doesn't display anymore c#

I have one textbox (textBox1) and panel (Panel1) I have code like this 我有一个文本框(textBox1)和面板(Panel1)我有这样的代码

Panel1.Controls.Add(textBox1)

so when I run it I can't see textbox anymore, If I do like this I can see textBox 所以当我运行它时,我再也看不到文本框,如果我这样做,我可以看到textBox

textBox1.Location  = Panel1.Location

can anyone tell me what's problem? 谁能告诉我什么问题?

When a textbox (or any control) is part of a panel the top left of the panel is point(0.0); 当文本框(或任何控件)是面板的一部分时,面板的左上角是point(0.0);

so when textBox1.Location = Panel1.Location the textbox probably falls out of view in the panel. 因此,当textBox1.Location = Panel1.Location时,文本框可能不在面板中。

try something like this instead/ 试试这样的东西代替/

        // 
        // 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;

I believe the reason you're not able to see the Textbox has to do with the Panel's properties. 我相信您看不到文本框的原因与面板的属性有关。 Try setting the AutoSize property to true and the AutoSizeMode property to GrowAndShrink . 尝试将AutoSize属性设置为true ,将AutoSizeMode属性设置为GrowAndShrink

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM