C#.NET中的面板控件 [英] Panel control in C#.NET
本文介绍了C#.NET中的面板控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,
谁能告诉我,如何使用 c#.NET 在winform上实现 面板控件 .
以及如何使它在特定事件上可见... ??
hey,
can any body tell me, how to implement a panel control on winform using c#.NET..??
and also how to make visible on a particular event...??
推荐答案
尝试 ^ ].
面板的动态创建
Dynamic Creation Of Panel
public void CreateMyPanel()
{
Panel panel1 = new Panel();
TextBox textBox1 = new TextBox();
Label label1 = new Label();
// Initialize the Panel control.
panel1.Location = new Point(56,72);
panel1.Size = new Size(264, 152);
// Set the Borderstyle for the Panel to three-dimensional.
panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
// Initialize the Label and TextBox controls.
label1.Location = new Point(16,16);
label1.Text = "label1";
label1.Size = new Size(104, 16);
textBox1.Location = new Point(16,32);
textBox1.Text = "";
textBox1.Size = new Size(152, 20);
// Add the Panel control to the form.
this.Controls.Add(panel1);
// Add the Label and TextBox controls to the Panel.
panel1.Controls.Add(label1);
panel1.Controls.Add(textBox1);
}
现在,假设您要在表单和单击事件上显示一个按钮,然后要显示该面板,
Now Suppose You Have A Button On Your Form And On The Click Event You Want To Show The Panel Then,
private void btnButton1_Click(object sender, EventArgs e)
{
panel1.visible = true;
}
如果对您有帮助,请接受此答案
Accept This Answer If It Has Helped You
将其从设计器的工具箱中拖到您的表单上,并适当地调整大小和放置它,或者:
Either drag it onto your form from the toolbox in the designer, and size and place it appropriately, or:
private Panel myPanel;
...
// Form load event, or constructor
myPanel = new Panel();
Controls.Add(myPanel);
myPanel.Controls.Add(new Button()); //Just for example
您可以通过Visible属性将其设置为可见或不可见.如果将面板显示为"Visible",则其包含的所有控件也将消失.
You can make it visible or invisible via the Visible property. If you make a panel Visible false, all it''s contained controls will disappear too.
这篇关于C#.NET中的面板控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文