[英]How to programitically add a panel winforms c#
i know this is kinda a silly question but how do i add panel to my winforms project at runtime i wanted a panel to show at startup but instead, i get nothing (No error messages were found) here is the code:我知道这有点愚蠢的问题,但是如何在运行时将面板添加到我的 winforms 项目中,我希望在启动时显示一个面板,但是,我什么也没得到(未找到错误消息)这里是代码:
private void Form1_Load(object sender, EventArgs e)
{
Panel panel = new Panel();
panel.Size = new Size(200, 100);
panel.Location = new Point(20,20);
this.Controls.Add(panel);
panel.Show();
}
ive tried using panel.Visibility = true;
我试过使用
panel.Visibility = true;
but its not working :(但它不起作用:(
Here is a sample for it.这是它的示例。 A panel alone is a container and not a visible component, you should have something in it.
单独的面板是一个容器而不是可见的组件,您应该在其中包含一些内容。 ie:
IE:
void Main()
{
Form f = new Form();
f.Show();
MessageBox.Show("Will add panel");
Panel p = new Panel { Size = new Size(200, 100), Location = new Point(20, 20) };
f.Controls.Add(p); // nothing would show
MessageBox.Show("Panel added. Continue to add something in panel");
Label l = new Label { Left=10, Top=10, Text="A label inside the panel" };
p.Controls.Add(l);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.