资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb.net控件学习 vbnet控件大全

如何学习VB.NET?

 Namespace

创新互联建站是一家专注于成都做网站、网站建设与策划设计,龙马潭网站建设哪家好?创新互联建站做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:龙马潭等地区。龙马潭做网站价格咨询:028-86922220

包含类似或相关功能的类的集合

Class

用来定义一个对象,包含对象的属性(包括变量)、方法(包括过程sub和函数)

Sub

子过程,可以把要使用的数据以参数形式传入,但不返回值

Function

函数,同样可以传参数,但要求有返回值

Property

属性过程,设置或返回对象的属性值

Return

结束当前sub或function,若是函数则返回一个函数值

Dim

声明或定义一个变量

New

创建一个新的实例对象

Nothing

表示一个变量没有值,与其他语言或数据库中的null等价

Me

当前类的实例对象的引用

Console

.NET

用于访问和操作命令窗口的类,主要用于命令行应用程序

Module

模块,定义一个不是类的代码块,但它同样可以包含变量和方法

运算符

算术运算符:/(除),\(整除),Mod(取模)

串联运算符:,+亦可

逻辑/按位运算符:Not、And、Or、Xor、AndAlso、OrElse

赋值运算符:= ,^= ,*= ,/= ,\= ,+= ,-= ,=,=,=

比较运算符: ,= , ,= ,= , ,Is ,IsNot ,Like

移位运算符: ,

其他运算符:AddressOf 运算符 ,GetType 运算符 ,函数表达式,If 运算符 ,TypeOf 运算符,Await 运算符

DirectCast 运算符

TryCast 运算符

New 运算符

*运算优先级:算术连接比较逻辑运算(用括号可改变优先级)

详细:

如果表达式中出现几种运算,将按照预先确定的称为“运算符优先级”的顺序计算和解析各个部分。

算术运算符和串联运算符

求幂 (^)

一元标识和非(+、–)

乘法和浮点除法(*、/)

整数除法 (\)

取模 (Mod)

加法和减法(+、–),字符串连接 (+)

字符串连接 ()

算术移位(、)

比较运算符

所有比较运算符(=、、、=、、=、Is、IsNot、Like、TypeOf...Is)

逻辑运算符和位运算符

非 (Not)

与 (And、AndAlso)

或 (Or、OrElse)

异或 (Xor)

vb.net入门之分组控件:GroupBox控件

我们对控件进行分组的原因不外乎三个

为了获得清晰的用户界面而将相关的窗体元素进行可视化分组

编程分组 如对单选按钮进行分组

为了在设计时将多个控件作为一个单元来移动

在中 有GroupBox Panel TabControl这三个控件可以实现上面所提到的三个分组目的 所以我们称它们为分组控件

这三个控件在功用上十分的相似 特别是GroupBox和Panel控件 只存在一点细微的差别而已(这个差别是 只有GroupBox控件可以显示标题 而只有Panel控件可以有滚动条) 这里我们就先来了解GroupBox控件的使用

GroupBox(控件组)控件一般是作为其他控件的组的容器的形式存在的 这样有利于用户识别 使界面变得更加友好(GroupBox控件相当于Visual Basic以前版本的Frame控件) 使用控件组控件可以将一个窗体中的各种功能进一步进行分类 例如 将各种选项按钮控件分隔开

当移动单个GroupBox控件时 它所包含的所有控件也将一起移动

在大多数情况下 对控件组控件没有实际的操作 我们用它对控件进行分组 通常没有必要响应它的事件 不过 它的Name Text和Font等属性可能会经常被修改 以适应应用程序在不同阶段的要求

GroupBox控件在工具箱中的图标如图所示

一 GroupBox控件的常用属性

Anchor和Dock 这两个属性是所有有用户界面的控件都有的定位属性 这里就不啰嗦了

Name属性 标识控件的对象名称

Text属性 显示在GroupBox控件右上方的标题文字 可以用来标识该控件组的描述

Font和ForeColor属性 用于改变GroupBox控件的文字大小以及文字的颜色 需要注意的时候 它不单改变GroupBox控件的Text属性的文字外观 同时也改变其内部控件的显示的Text属性的文字外观

二 创建一组控件

在窗体上放置GroupBox控件 从工具箱中拖放一个GroupBox控件到窗体上的合适位置 调整大小

在属性窗口中改变GroupBox控件的Text属性 作为它的标题

在GroupBox控件内拖放其它需要的控件 例如RadioButton控件

设置示例 如图一所示

图一 用控件组控件对单选按钮分组

我们在拖动单个GroupBox控件的时候 它内部的控件也会随着移动 以保持和GroupBox的相对位置不变 同理 删除GroupBox控件时 它所包含的所有控件也会被删除掉

当我们调整GroupBox控件所包含的控件的Anchor和Dock属性的时候 其参照物将不是Form窗体 而是GroupBox控件了

三 编程添加GroupBox控件以及它所包含的控件

虽然GroupBox控件是在设计时用视图设计布局效果最好 但是无可避免地 很多特殊情况下也是需要在运行做添加控件到控件组中的 这里我们就用代码来完成上图一界面的绘制

动态添加控件一般需要经过下面三个步骤

创建要添加的控件实例

设置新控件的属性

将控件添加到父控件的 Controls 集合

在Form 代码的任意位置增加初始化控件的过程InitializeControl() 代码如下所示

Sub InitializeControl()

首先添加Label和TextBox控件

Dim Label As New System Windows Forms Label

Dim TextBox As New System Windows Forms TextBox

Label

Label Location = New System Drawing Point( )

Label Name = Label

Label Size = New System Drawing Size( )

Label TabIndex =

Label Text = 户主姓名

TextBox

TextBox Location = New System Drawing Point( )

TextBox Name = TextBox

TextBox Size = New System Drawing Size( )

TextBox TabIndex =

TextBox Text =

把它们添加到父控件Form 的Controls集合中

Me Controls Add(TextBox )

Me Controls Add(Label )

添加三个GroupBox控件

Dim GroupBox As New System Windows Forms GroupBox

Dim GroupBox As New System Windows Forms GroupBox

Dim GroupBox As New System Windows Forms GroupBox

GroupBox

GroupBox BackColor = System Drawing SystemColors Control

GroupBox Location = New System Drawing Point( )

GroupBox Name = GroupBox

GroupBox Size = New System Drawing Size( )

GroupBox TabIndex =

GroupBox TabStop = False

GroupBox Text = 性别

GroupBox

GroupBox Location = New System Drawing Point( )

GroupBox Name = GroupBox

GroupBox Size = New System Drawing Size( )

GroupBox TabIndex =

GroupBox TabStop = False

GroupBox Text = 单元

GroupBox

GroupBox Location = New System Drawing Point( )

GroupBox Name = GroupBox

GroupBox Size = New System Drawing Size( )

GroupBox TabIndex =

GroupBox TabStop = False

GroupBox Text = 楼层

把它们添加到父控件Form 的Controls集合中

Me Controls Add(GroupBox )

Me Controls Add(GroupBox )

Me Controls Add(GroupBox )

添加RadioButton控件并分别绘制在GroupBox控件内

Dim RadioButton As New System Windows Forms RadioButton

Dim RadioButton As New System Windows Forms RadioButton

Dim RadioButton As New System Windows Forms RadioButton

Dim RadioButton As New System Windows Forms RadioButton

Dim RadioButton As New System Windows Forms RadioButton

Dim RadioButton As New System Windows Forms RadioButton

Dim RadioButton As New System Windows Forms RadioButton

Dim RadioButton As New System Windows Forms RadioButton

Dim RadioButton As New System Windows Forms RadioButton

Dim RadioButton As New System Windows Forms RadioButton

RadioButton

RadioButton Location = New System Drawing Point( )

RadioButton Name = RadioButton

RadioButton Size = New System Drawing Size( )

RadioButton TabIndex =

RadioButton Text = 男性

RadioButton

RadioButton Location = New System Drawing Point( )

RadioButton Name = RadioButton

RadioButton Size = New System Drawing Size( )

RadioButton TabIndex =

RadioButton Text = 女性

RadioButton

RadioButton Location = New System Drawing Point( )

RadioButton Name = RadioButton

RadioButton Size = New System Drawing Size( )

RadioButton TabIndex =

RadioButton Text = 二单元

RadioButton

RadioButton Location = New System Drawing Point( )

RadioButton Name = RadioButton

RadioButton Size = New System Drawing Size( )

RadioButton TabIndex =

RadioButton Text = 三单元

RadioButton

RadioButton Location = New System Drawing Point( )

RadioButton Name = RadioButton

RadioButton Size = New System Drawing Size( )

RadioButton TabIndex =

RadioButton Text = 一单元

RadioButton

RadioButton BackColor = System Drawing SystemColors Control

RadioButton Location = New System Drawing Point( )

RadioButton Name = RadioButton

RadioButton Size = New System Drawing Size( )

RadioButton TabIndex =

RadioButton Text = 四单元

RadioButton

RadioButton Location = New System Drawing Point( )

RadioButton Name = RadioButton

RadioButton Size = New System Drawing Size( )

RadioButton TabIndex =

RadioButton Text = 二楼

RadioButton

RadioButton Location = New System Drawing Point( )

RadioButton Name = RadioButton

RadioButton Size = New System Drawing Size( )

RadioButton TabIndex =

RadioButton Text = 三楼

RadioButton

RadioButton Location = New System Drawing Point( )

RadioButton Name = RadioButton

RadioButton Size = New System Drawing Size( )

RadioButton TabIndex =

RadioButton Text = 一楼

RadioButton

RadioButton BackColor = System Drawing SystemColors Control

RadioButton Location = New System Drawing Point( )

RadioButton Name = RadioButton

RadioButton Size = New System Drawing Size( )

RadioButton TabIndex =

RadioButton Text = 四楼

分别把它们添加到父控件GroupBox的Controls集合中

GroupBox Controls Add(RadioButton )

GroupBox Controls Add(RadioButton )

GroupBox Controls Add(RadioButton )

GroupBox Controls Add(RadioButton )

GroupBox Controls Add(RadioButton )

GroupBox Controls Add(RadioButton )

GroupBox Controls Add(RadioButton )

GroupBox Controls Add(RadioButton )

GroupBox Controls Add(RadioButton )

GroupBox Controls Add(RadioButton )

End Sub

把上一页的代码复制添加后 把控件初始化过程InitializeControl()过程添加到Form 的New构造函数中 如下图二所示

图二 在New构造函数中添加过程InitializeControl()

现在按F 运行 Form 的窗体控件布局(如下图三所示)是不是和我们手工布局的图一的布局是一样的呢?

lishixinzhi/Article/program/ASP/201311/21749

vb.net中treeview控件用法

由于每个 TreeNode 都可以包含其他 TreeNode 对象的集合,您可能会在循环访问集合时觉得很难确定自己在树结构中的位置。您可以使用 PathSeparator 字符串值来分析 TreeNode.FullPath 字符串,以确定 TreeNode 标签的起始和终止位置。

可以在树节点旁显示图像,方法是将一个 ImageList 分配给 ImageList 属性,然后通过引用 Image 在 ImageList 中的索引值来分配该 Image。使用下面的属性分配图像:

将 ImageIndex 属性设置为当树节点未选定时所显示的 Image 的索引值。

将 SelectedImageIndex 属性设置为当树节点被选定时要显示的 Image 的索引值。

ImageIndex 和 SelectedImageIndex 属性值所引用的图像是所有分配给 Nodes 集合的树节点显示的默认图像。每个树节点都可以通过设置 TreeNode.ImageIndex 和 TreeNode.SelectedImageIndex 属性来取代默认的图像。

树节点可以展开,以显示下一级子树节点。用户可以在 TreeNode 旁显示加号 (+) 按钮时通过单击加号 (+) 按钮来展开 TreeNode,或者可以通过调用 TreeNode.Expand 方法来展开 TreeNode。若要展开 Nodes 集合中的所有子树节点级别,请调用 ExpandAll 方法。若要折叠子 TreeNode 级别,可以调用 TreeNode.Collapse 方法,也可以在 TreeNode 旁显示减号 (-) 按钮时按减号 (-) 按钮。还可以通过调用 TreeNode.Toggle 方法在展开和折叠状态之间切换。

树节点可以选择性地显示复选框。若要显示复选框,请将 TreeView 的 CheckBoxes 属性设置为 true。对于处于选中状态的树节点,Checked 属性设置为 true。

注意

从 BeforeCheck 或 AfterCheck 事件内设置 TreeNode.Checked 属性将导致该事件被多次引发并可能产生意外行为。例如,您可以在递归更新子节点时在事件处理程序中设置 Checked 属性,以便用户不必逐个展开并选中每个节点。如果未将 TreeViewEventArgs 的 Action 属性设置为 TreeViewAction.Unknown,则若要防止该事件被多次引发,需为仅执行递归代码的事件处理程序添加逻辑。有关如何进行此操作的示例,请参见 AfterCheck 或 BeforeCheck 事件的示例部分。

通过设置 TreeView 控件的一些显示和样式属性,可以更改此控件的外观。如果将 ShowPlusMinus 设置为 true,则会分别在每个可展开或折叠的 TreeNode 旁显示加号或减号按钮。如果将 ShowRootLines 属性设置为 true,TreeView 则会显示联接所有根树节点之间的连线。通过将 ShowLines 属性设置为 true,可以显示子树节点与其根节点之间的连线。如果将 HotTracking 属性设置为 true,那么当鼠标指针移过树节点标签时,树节点标签的外观将发生变化。如果启用热跟踪,树节点标签将具有超链接的外观。也可以完全自定义 TreeView 控件的外观。若要执行此操作,请将 DrawMode 属性设置为 TreeViewDrawMode.Normal 以外的值并处理 DrawNode 事件。

注意

在运行时设置 CheckBoxes、Scrollable、ImageIndex 和 SelectedImageIndex 属性时,将重新创建 TreeView 句柄(请参见 Control.RecreateHandle)以更新控件的外观。这将折叠除选定的 TreeNode 之外的所有树节点。

下面的代码示例阐释了如何使用 TreeView 控件。

Private Sub InitializeTreeView()

treeView1.BeginUpdate()

treeView1.Nodes.Add("Parent")

treeView1.Nodes(0).Nodes.Add("Child 1")

treeView1.Nodes(0).Nodes.Add("Child 2")

treeView1.Nodes(0).Nodes(1).Nodes.Add("Grandchild")

treeView1.Nodes(0).Nodes(1).Nodes(0).Nodes.Add("Great Grandchild")

treeView1.EndUpdate()

End Sub

From MSDN


网站名称:vb.net控件学习 vbnet控件大全
当前网址:http://cdkjz.cn/article/ddojodo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220