




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
入门分组控件:Panel控件的使用2008-1-21 20:06:00查看学习心得 我们对控件进行分组的原因不外乎三个:1、为了获得清晰的用户界面而将相关的窗体元素进行可视化分组。2、编程分组,如对单选按钮进行分组。3、为了在设计时将多个控件作为一个单元来移动。在中,有GroupBox、Panel、TabControl这三个控件可以实现上面所提到的三个分组目的,所以我们称它们为分组控件。前面我们了解了GroupBox(控件组)控件(入门分组控件:GroupBox控件的使用)的使用,这里我们将来看看下怎么使用Panel(也称面板)控件。实际上,Panel很类似于GroupBox,其区别是:只有GroupBox控件可以显示标题,而只有Panel控件可以有滚动条。Panel控件在工具箱中的图标如图所示:。一、Panel控件的常用属性1、Anchor和Dock:这两个属性是所有有用户界面的控件都有的定位属性。2、Name属性:标识控件的对象名称3、BorderStyle属性:指示Panel控件的边框样式,共有三个枚举值:BorderStyle.None(默认)无边框。BorderStyle.Fixed3D三维边框BorderStyle.FixedSingle单行边框此外还可以通过BackColor、BackgroundImage属性来改变Panel控件的外观。4、Font和ForeColor属性,用于改变Panel控件内部文字的大小与文字的颜色,需要注意的时候,这里改变的是其内部控件的显示的Text属性的文字外观。5、AutoScroll属性:该属性指示当控件超出Panel显示的区域时,是否自动出现滚动条,默认为False。二、创建一组控件1、在窗体上放置Panel控件。从工具箱中拖放一个Panel控件到窗体上的合适位置,调整大小。2、因为Panel控件没有Text属性来标记自己,所以我们一般可以在它的上面添加一个Label控件来标记它。3、在Panel控件内拖放其它需要的控件,例如RadioButton控件。4、设置Panel控件的外观属性。4、设置示例在窗体上设置两个Panel控件,分别用2个Label控件来标记它们,每个Panel控件中放置所需的RadioButton控件。如图一所示:注意:两个Panel控件的AutoScroll属性都设置为True了。5、我们在拖动单个Panel控件的时候,它内部的控件也会随着移动,以保持和Panel的相对位置不变。同理,删除Panel控件时,它所包含的所有控件也会被删除掉。6、当我们调整Panel控件所包含的控件的Anchor和Dock属性的时候,其参照物将不是Form窗体,而是Panel控件了。7、当AutoScroll 属性为 True 的时候,在设计界面中我们也可以拉动出现的滚动条。三、编程添加Panel控件以及它所包含的控件动态添加控件一般需要经过下面三个步骤:1、创建要添加的控件实例2、设置新控件的属性。3、将控件添加到父控件的 Controls 集合。在Form1代码的任意位置增加初始化控件的过程InitializeControl(),代码如下所示:Sub InitializeControl()Dim Panel1 As New System.Windows.Forms.PanelDim Label1 As New System.Windows.Forms.LabelDim Label2 As New System.Windows.Forms.LabelDim Panel2 As New System.Windows.Forms.PanelDim RadioButton1 As New System.Windows.Forms.RadioButtonDim RadioButton2 As New System.Windows.Forms.RadioButtonDim RadioButton3 As New System.Windows.Forms.RadioButtonDim RadioButton4 As New System.Windows.Forms.RadioButtonDim RadioButton5 As New System.Windows.Forms.RadioButtonDim RadioButton6 As New System.Windows.Forms.RadioButtonDim RadioButton7 As New System.Windows.Forms.RadioButtonDim RadioButton8 As New System.Windows.Forms.RadioButtonPanel1Panel1.AutoScroll = TruePanel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3DPanel1.Controls.Add(RadioButton4)Panel1.Controls.Add(RadioButton3)Panel1.Controls.Add(RadioButton2)Panel1.Controls.Add(RadioButton1)Panel1.Location = New System.Drawing.Point(16, 32)Panel1.Name = Panel1Panel1.Size = New System.Drawing.Size(112, 104)Panel1.TabIndex = 0Label1Label1.BackColor = System.Drawing.Color.WhiteLabel1.Font = New System.Drawing.Font(宋体, 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte)Label1.ForeColor = System.Drawing.Color.RedLabel1.Location = New System.Drawing.Point(16, 15)Label1.Name = Label1Label1.Size = New System.Drawing.Size(112, 17)Label1.TabIndex = 1Label1.Text = 一单元Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenterLabel2Label2.BackColor = System.Drawing.Color.WhiteLabel2.Font = New System.Drawing.Font(宋体, 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte)Label2.ForeColor = System.Drawing.Color.RedLabel2.Location = New System.Drawing.Point(136, 14)Label2.Name = Label2Label2.Size = New System.Drawing.Size(112, 18)Label2.TabIndex = 2Label2.Text = 二单元Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenterPanel2Panel2.AutoScroll = TruePanel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3DPanel2.Controls.Add(RadioButton5)Panel2.Controls.Add(RadioButton6)Panel2.Controls.Add(RadioButton7)Panel2.Controls.Add(RadioButton8)Panel2.Location = New System.Drawing.Point(136, 32)Panel2.Name = Panel2Panel2.Size = New System.Drawing.Size(112, 104)Panel2.TabIndex = 3RadioButton1RadioButton1.Location = New System.Drawing.Point(8, 13)RadioButton1.Name = RadioButton1RadioButton1.Size = New System.Drawing.Size(48, 16)RadioButton1.TabIndex = 0RadioButton1.Text = 101RadioButton2RadioButton2.Location = New System.Drawing.Point(8, 39)RadioButton2.Name = RadioButton2RadioButton2.Size = New System.Drawing.Size(48, 16)RadioButton2.TabIndex = 1RadioButton2.Text = 102RadioButton3RadioButton3.Location = New System.Drawing.Point(8, 65)RadioButton3.Name = RadioButton3RadioButton3.Size = New System.Drawing.Size(48, 16)RadioButton3.TabIndex = 2RadioButton3.Text = 103RadioButton4RadioButton4.Location = New System.Drawing.Point(8, 91)RadioButton4.Name = RadioButton4RadioButton4.Size = New System.Drawing.Size(48, 16)RadioButton4.TabIndex = 3RadioButton4.Text = 104RadioButton5RadioButton5.Location = New System.Drawing.Point(8, 91)RadioButton5.Name = RadioButton5RadioButton5.Size = New System.Drawing.Size(48, 16)RadioButton5.TabIndex = 7RadioButton5.Text = 404RadioButton6RadioButton6.Location = New System.Drawing.Point(8, 65)RadioButton6.Name = RadioButton6RadioButton6.Size = New System.Drawing.Size(48, 16)RadioButton6.TabIndex = 6RadioButton6.Text = 303RadioButton7RadioButton7.Location = New System.Drawing.Point(8, 39)RadioButton7.Name = RadioButton7RadioButton7.Size = New System.Drawing.Size(48, 16)RadioButton7.TabIndex = 5RadioButton7.Text = 202RadioButton8RadioButton8.Location = New System.Drawing.Point(8, 13)RadioButton8.Name = RadioButton8RadioButton8.Size = New System.Drawing.Size(48, 16)RadioButton8.TabIndex = 4RadioButton8.Text = 201Form1AutoScaleBaseSize = New Sys
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 企业用电安全培训
- 企业春节安全培训课件
- 热压模具清理管理办法
- 网络发票管理办法试行
- 老实征兵测试题及答案2025
- 2025年中医针灸学子午流注应用测试卷及答案解析
- 出纳银行结算业务课件
- 2025合同范本广告代理合同模板
- 出口退税课件原理
- 党员集中培训考试题目及答案
- 2025浙江省知识产权研究与服务中心编外招聘12人笔试模拟试题及答案解析
- 2025国资国企穿透式监管白皮书
- 肺中下叶恶性肿瘤的个案护理
- 小学法制课教学课件下载
- 年产8万吨DN900-DN1600mm球墨铸管项目可行性研究报告
- 商家智能体产品手册和操作指南
- 幼儿园手工介绍课件
- 电力营销考试题库及答案
- 监察法专题培训课件
- 人证网约车考试题目及答案
- 人教版五年级数学上册第三单元小数除法教学设计(表格式)和单元测试题
评论
0/150
提交评论