Panel控件



命名空间:System.Windows.Forms
程序集:System.Windows.Forms(在 system.windows.forms.dll 中)

[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class Panel : ScrollableControl

Panel 是一个包含其他控件的控件。可以使用 Panel 来组合控件的集合,例如一组 RadioButton 控件。与其他容器控件(如 GroupBox 控件)一样,如果 Panel 控件的 Enabled 属性设置为 false,则也会禁用包含在 Panel 中的控件。

默认情况下,Panel 控件在显示时没有任何边框。可以用 BorderStyle 属性提供标准或三维的边框,将窗面板区与窗体上的其他区域区分开。因为 Panel 控件派生于 ScrollableControl 类,所以可以用 AutoScroll 属性来启用 Panel 控件中的滚动条。当 AutoScroll 属性设置为 true 时,使用所提供的滚动条可以滚动显示 Panel 中(但不在其可视区域内)的所有控件。

Panel 控件不显示标题。如果需要与 Panel 类似可显示标题的控件,请参见 GroupBox 控件

下面的代码示例创建一个 Panel 控件,并向 Panel 添加一个 Label 和一个 TextBoxPanel 控件显示有三维边框,以将 Panel 控件所在的区域与窗体上其他的对象区分开。此示例需要它所定义的方法是从现有窗体中调用的,并且已将 System.Drawing 命名空间添加到该窗体的源代码中。

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);
}



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值