资讯

精准传达 • 有效沟通

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

vb点虐 入门 vbnet入门经典第八版pdf 百度网盘

vb点虐 入门之分组控件:GroupBox控件

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

蒙自网站制作公司哪家好,找成都创新互联公司!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设公司等网站项目制作,到程序开发,运营维护。成都创新互联公司从2013年开始到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联公司

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

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

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

在中 有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入门--Imports 语句

导入在引用的项目和程序集中定义的命名空间或编程元素 此外 导入在同一个项目中定义的命名空间或元素

Imports [ aliasname = ] namespace or Imports [ aliasname = ] namespace element

各部分说明

aliasname

可选 导入别名 或名称 代码可按该名称而不是完全限定字符串来引用 namespace

namespace

必选 所导入命名空间的完全限制名称 可以为嵌套到任意级别的命名空间的字符串

element

可选 命名空间中所声明编程元素的名称 可以为任何容器元素

备注

每个源文件可以包含任意数量的 Imports 语句 这些语句必须位于任何选项声明(如 Option Strict 语句)之后 任何编程元素声明(如 Module 或 Class 语句)之前

只能在文件级别使用 Imports 这意味着导入的声明上下文必须是源文件 而不能是命名空间 类 结构 模块 接口 过程或块

当需要使用在一个或多个命名空间中声明的同名项目时 导入别名十分有用

请注意 Imports 语句不会将其他项目和程序集中的元素提供给您的项目使用 导入不会取代对引用的设置 它只是使那些已经可用于项目的名称不再需要加以限定

规则

别名 不应使用与 aliasname 相同的名称在模块级别声明成员 如果这样做 Visual Basic 编译器只对声明的成员使用 aliasname 而不再将其识别为导入别名

命名空间名称 可以提供单个命名空间名称 也可以提供嵌套命名空间的字符串 每个嵌套命名空间都通过句点 ( ) 与下一个更高级别的命名空间分隔 如下面的示例中所述

Imports System Collections Generic

元素类型 如果提供 element 它必须表示 容器元素 即可包含其他元素的编程元素 容器元素包括类 结构 模块 接口和枚举

行为

范围 Imports 语句所提供元素的范围取决于是否指定了 element 如果仅指定了 namespace 则该命名空间中所有具有唯一名称的成员以及该命名空间内容器元素的成员无需限定即可使用 如果既指定了 namespace 又指定了 element 则只有该元素的成员无需限定即可使用

限定 命名空间或容器元素外部的代码通常必须使用该命名空间或容器元素的名称来限定成员的名称 除非您的项目要访问具有相同名称的另一个成员 否则使用 Imports 语句后将不必进行此类限定 在这种情况下 您可以在每个 Imports 语句中指定一个 aliasname 然后 您只需导入别名即可限定具有相同名称的成员

示例

下面的示例将导入 Microsoft VisualBasic Strings 类并给其分配一个别名 str 该别名可用于访问 Left 方法

Place Imports statements at the top of your program Imports str = Microsoft VisualBasic Strings Visual BasicClass testClass    Sub showHello()    Display only the word Hello    MsgBox(str Left( Hello World ))    End Sub End Class lishixinzhi/Article/program/ASP/201311/21880

VB.Net编程入门之Hello World(4)

四 第一个Visual Basic Net程序 Hello World!

如果你没有Visual Studio Net 你也可以通过一个文本编辑器和从微软下载安装 Net Frame Work SDK来编写Visual Basic Net 文本编辑器来编辑Visual Basic Net源程序 安装下载的 Net FrameWork SDK后就会用以Visual Basic Net的编译器Vbc exe 通过这个编译器就可以编译 联接用文本编辑器编辑的Visual Basic Net源文件 虽然这种做法能够让我们更加了解Visual Basic Net的运行机制和一些底层的机理 但却很难推广 一方面是Visual Studio Net的确是太优秀了 利用文本编辑器很难实现如资源编辑 组件编辑等操作 另外一方面 Visual Basic Net源文件结构相对复杂 用文本编辑器编写的代码会导致大量的错误 并且这些错误有很难查出来 而利用Visual Studio Net来开发Visual Basic Net应用程序就能够大大避免上述的尴尬 并且能够方便的调试编程中出现的各种警告 错误

本系列文章中介绍程序的编写 调试和运行的软件环境

( ) 视窗 服务器版

( ) Visual Studio Net 企业级结构设计版

用Visual Studio Net开发 Hello World! 程序

我们知道 Hello World 一般是命令行程序 而这种程序在Visual Studio Net中被称为 控制台程序 下面是Visual Studio Net编写控制台 Hello World! 程序的具体步骤

( ) 启动Visual Studio Net

( ) 选择菜单【文件】|【新建】|【项目】后 弹出【新建项目】对话框

( ) 将【项目类型】设置为【Visual Basic项目】

( ) 将【模板】设置为【控制台应用程序】

( ) 在【名称】文本框中输入【Hello World】

( ) 在【位置】的文本框中输入【E:\VS NET项目】 然后单击【确定】按钮 则Visual Studio Net会按照上面设定的参数创建一个控制台应用程序项目

( ) 在【解决方案资源管理器】窗口中 双击Module vb文件 进入Module vb文件的编辑界面

( ) Visual Studio Net已经为产生Main()函数 在系统创建的Main()函数中加入下面一行代码就可以了

Console WriteLine ( Hello World! )

( ) 选择【文件】|【保存Module vb】菜单或者按快捷键Ctrl+S 保存所做的修改

( ) 此时单击快捷键Ctrl+F 运行程序就可以得到运行界面

通过以上可见利用Visual Studio Net编写控制台 Hello World! 程序 自始至终只需输入一行代码 Visual Studio Net自动实现源程序编译 联接等过程 避免在命令行提示符下敲编译命令的苦恼 不仅如此Visual Studio Net自动的语法检测 既给程序员带来便捷 又避免了因为拼写造成的不必要的错误 等等这些都比起用行编辑器来编写Visual Basic Net程序要方便 简洁

Hello World! 程序是一个控制台程序 而后面的章节中程序的类型主要是Windows应用程序(一般简称WinForm程序) 利用Visual Studio Net编写WinForm应用程序和控制台应用程序步骤基本相似 下面就介绍一下Visual Studio Net编写WinForm类型的 Hello World 程序的基本步骤

Hello World! 程序的WinForm版本

Hello World! 程序的WinForm版本的可是我取的名字 此程序同样也是输出 Hello World! 字符串 只不过不是在命令提示行中实现 而是通过单击程序中的按钮 会弹出一个消息框 并在消息框中显示 Hello World! 字符串 下面是 Hello World! 程序的WinForm版本的具体步骤

( ) 启动Visual Studio Net

( ) 选择菜单【文件】|【新建】|【项目】后 弹出【新建项目】对话框

( ) 将【项目类型】设置为【Visual Basic项目】

( ) 将【模板】设置为【Windows应用程序】

( ) 在【名称】文本框中输入【Hello_World程序WinForm版】

( ) 在【位置】的文本框中输入【E:\VS NET项目】 然后单击【确定】按钮 则Visual Studio Net会按照上面设定的参数创建一个Windows应用程序项目

( ) 选择【工具箱】中的【Windows窗体组件】 并从中拖入一个Button组件到【Form vb(设计)】窗口 此组件名称为button 双击拖入的button 组件 Visual Studio Net会切换窗口到Form 的设计窗口 并自动产生button 的Click事件对应的代码

( ) 在button 的Click事件的代码区添加下列代码 下列代码的功能是弹出 Hello World! 提示框

MessageBox Show ( Hello World! )

( ) 选择【文件】|【保存Form vb】菜单或者按快捷键Ctrl+S 保存所做的修改

( ) 选择【生成】|【生成Hello_World程序WinForm版】菜单 则Visual Studio Net会自动编译 连接源程序 并生成Hello_World程序WinForm版的执行文件

( ) 选择【调试】|【启动】菜单或者单击快捷键 F 则开始运行Hello_World程序WinForm版程序 单击程序中的【button 】按钮 则弹出 Hello World! 提示框

至此Hello_World程序WinForm版程序的全部编写工作就完成了 对于其他的WinForm程序 其编写的基本步骤是相似的 只不过程序中涉及到更多的组件 类和其他的调用 无非是上面这些操作步骤的变形和再组合

五.总结

lishixinzhi/Article/program/net/201311/14627


文章题目:vb点虐 入门 vbnet入门经典第八版pdf 百度网盘
分享URL:http://cdkjz.cn/article/ddjsjhp.html
多年建站经验

多一份参考,总有益处

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

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

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