
正文
vb.net入门网 vbnet教程
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
vb.net 整个网站开发教程
建议到书店去看看vb.net入门网,大一点vb.net入门网的书店,这样的书挺多的,网上的大多都不太好,也不完整,最好找那种有开发步骤的,而不是净粘一堆代码的,这种东西有个大体框架,知道怎么个过程就够vb.net入门网了,具体开发细节一步步摸索,教程里的东西大多都运行不vb.net入门网了,再说一步步照着做也没什么长进
相关问答
Q1: VB.NET菜单设计初级入门[3]
五.绘制个性化菜单
先执行以下操作步骤 下列步骤是通过菜单编辑器设计一个简单的菜单 为后面重新绘制做基础
启动Visual Studio Net
选择菜单【文件】|【新建】|【项目】后 弹出【新建项目】对话框
将【项目类型】设置为【Visual Basic项目】
将【模板】设置为【Windows应用程序】
在【名称】文本框中输入【自己画菜单】
在【位置】的文本框中输入【E:\VS NET项目】 然后单击【确定】按钮 这样在 E:\VS NET项目 目录中就产生了名称为 自己画菜单 的文件夹 并在里面创建了名称为 自己画菜单 的项目文件
把Visual Studio Net的当前窗口切换到【Form vb(设计)】窗口 并从【工具箱】中的【Windows窗体组件】选项卡中往Form 窗体中拖入下列组件
一个MainMenu组件 名称为 MainMenu
选中 MainMenu 组件 单击鼠标右键 在弹出的菜单中选择 编辑菜单 并按照图 所示界面设计菜单
图 【自己画菜单】项目设计界面之一
此时保存上述步骤 并单击快捷键F 则得到图 所示界面
图 【自己画菜单】运行界面之一
这样通过菜单编辑器就完成了一个非常普通的菜单 下面就对此菜单进行改造 在改造之前 要先设定项目中的三个MenuItem类实例的OwnerDraw属性值为 True 因为只有此属性值为 True 才会触发绘制菜单时所需要的DrawItem事件和MeasureItem事件 之后再在上面项目的基础上执行下一步操作
把Visual Stuido Net的当前窗口切换到Form vb的代码编辑窗口 并在InitializeComponent过程之后添加下列代码 下列代码是绘制 文件 菜单项 其作用是改变 文件 菜单项的字体 大小和菜单项的 其具体的绘制方法请参考下列代码中的注释
Private Sub MenuItem _DrawItem ( ByVal sender As Object ByVal e As System Windows Forms DrawItemEventArgs ) Handles MenuItem DrawItem Dim rfBound As RectangleF = New RectangleF ( e Bounds X e Bounds Y e Bounds Width e Bounds Height ) 根据DrawItemEventArgs参数获得菜单项矩形区域并存储到RectangleF类型实例中 Dim rfBound As Rectangle = New Rectangle ( e Bounds X e Bounds Y e Bounds Width e Bounds Height ) 根据DrawItemEventArgs参数获得菜单项矩形区域并存储到Rectangle类型实例中 Rectangle类型实例和RectangleF类型实例差不多 但在后面代码中绘制菜单的函数是有区别的 e Graphics FillRectangle(New SolidBrush(Color LightGreen) rfBound) 以LightGreen色彩填充MenuItem 菜单项对应的矩形区域 Dim s As MenuItem = CType ( sender MenuItem ) Dim s As String = s Text 获得MenuItem 菜单项的名称 Dim sfTemp As StringFormat = New StringFormat ( ) sfTemp Alignment = StringAlignment Center 设定要画的菜单名称的对齐方式 中间对齐 e Graphics DrawString ( s New Font ( 宋体 FontStyle Bold ) New SolidBrush ( Color Black ) rfBound sfTemp ) 以中间对齐方式 指定字体 大小 在指定的矩形区域重画菜单 If e State = ( DrawItemState NoAccelerator Or DrawItemState Selected ) Then 根据菜单项的当前绘制状态来绘制菜单项 e Graphics FillRectangle ( New SolidBrush ( Color LightYellow ) rfBound ) 对菜单项所在的矩形区域进行色彩填充 e Graphics DrawString ( s New Font ( 宋体 FontStyle Bold ) New SolidBrush ( Color Black ) rfBound sfTemp ) 对菜单项名称绘制 End If e DrawFocusRectangle ( ) 在 DrawItemEventArgs参数得到矩形范围内绘制聚焦框 e Graphics DrawRectangle ( New Pen ( New SolidBrush ( Color Black ) ) rfBound ) 对菜单项的矩形区域绘制矩形框End Sub
操作完成后 保存修改 此时再单击快捷键F 运行程序 可得到如图 所示的界面
图 【自己画菜单】运行界面之二
可见绘制的 文件 菜单项并没有完全显示出来 并且后面的菜单项也没有显示 这是因为菜单项的显示区域并没有设定 而缺省的空间又不能完全显示造成的 设定菜单项的显示区域大小是通过MeasureItem事件来完成的 具体操作是在MenuItem 的DrawItem事件后添加下列代码 下列代码是是定义MenuItem 的MeasureItem事件 在此事件中设定菜单项的宽度(当然也可以设定高度等)
Private Sub MenuItem _MeasureItem ( ByVal sender As Object ByVal e As System Windows Forms MeasureItemEventArgs ) Handles MenuItem MeasureItem e ItemWidth = 设定菜单项的宽度End Sub
保存上述修改后 单击快捷键F 运行程序可得到图 所示界面
图 【自己画菜单】运行界面之三
可见 文件 菜单项就算绘制出来了 由于其他菜单项没有绘制处理 所以也未显示 其他菜单项的绘制方法和 文件 菜单项的绘制方法基本相似 以下是在上述完成的基础上 对其他菜单项进行绘制 从而得到图 所示菜单的具体实现步骤
图 【自己画菜单】运行界面之四
在Form vb中的MenuItem 的MeasureItem事件处理程序之后添加下列代码 下列代码是定义MenuItem 的DrawItem事件 其功能是对 新建 菜单项重新绘制
Private Sub MenuItem _DrawItem ( ByVal sender As Object ByVal e As System Windows Forms DrawItemEventArgs ) Handles MenuItem DrawItem Dim rfBound As RectangleF = New RectangleF ( e Bounds X e Bounds Y e Bounds Width e Bounds Height ) 根据DrawItemEventArgs参数获得菜单项矩形区域并存储到RectangleF类型实例中 Dim rfBound As Rectangle = New Rectangle ( e Bounds X e Bounds Y e Bounds Width e Bounds Height ) 根据DrawItemEventArgs参数获得菜单项矩形区域并存储到Rectangle类型实例中 Rectangle类型实例和RectangleF类型实例差不多 但在后面代码中绘制菜单的函数是有区别的 e Graphics FillRectangle ( New SolidBrush ( Color LightGray ) rfBound ) Dim s As MenuItem = CType ( sender MenuItem ) Dim s As String = s Text 获得菜单项对应的文本名称 Dim sfTemp As StringFormat = New StringFormat ( ) sfTemp Alignment = StringAlignment Center 设定文本在矩形区域的对齐方式 sfTemp LineAlignment = StringAlignment Center Dim rcText As RectangleF = rfBound rcText Width = e Graphics DrawString ( s New Font ( 宋体 ) New SolidBrush ( Color Blue ) rcText sfTemp ) e Graphics DrawRectangle ( New Pen ( New SolidBrush ( Color LightGray ) ) rfBound ) If e State = ( DrawItemState NoAccelerator Or DrawItemState Selected ) Thene Graphics FillRectangle ( New SolidBrush ( Color LightYellow ) rfBound ) e Graphics DrawString ( s New Font ( 宋体 FontStyle Bold Or FontStyle Underline ) New SolidBrush ( Color Red ) rcText sfTemp ) e Graphics DrawRectangle ( New Pen ( New SolidBrush ( Color Black ) ) rfBound ) e DrawFocusRectangle ( ) End IfEnd Sub
MenuItem 的DrawItem事件处理代码之后添加下列代码 下列代码是定义MenuItem 的MeasureItem事件 在此事件中实现设定 新建 菜单项的长度和高度
Private Sub MenuItem _MeasureItem ( ByVal sender As Object ByVal e As System Windows Forms MeasureItemEventArgs ) Handles MenuItem MeasureItem e ItemWidth = 设定菜单项的宽度 e ItemHeight = 设定菜单项的高度End Sub
在完成上述操作步骤后 再在MenuItem 的MeasureItem事件处理程序之后添加下列代码 下列代码是定义MenuItem 的DrawItem事件 其功能是对 打开 菜单项重新绘制
Private Sub MenuItem _DrawItem ( ByVal sender As Object ByVal e As System Windows Forms DrawItemEventArgs ) Handles MenuItem DrawItemDim rfBound As RectangleF = New RectangleF ( e Bounds X e Bounds Y e Bounds Width e Bounds Height ) 根据DrawItemEventArgs参数获得菜单项矩形区域并存储到RectangleF类型实例中Dim rfBound As Rectangle = New Rectangle ( e Bounds X e Bounds Y e Bounds Width e Bounds Height ) 根据DrawItemEventArgs参数获得菜单项矩形区域并存储到Rectangle类型实例中 Rectangle类型实例和RectangleF类型实例差不多 但在后面代码中绘制菜单的函数是有区别的Dim s As MenuItem = CType ( sender MenuItem ) Dim s As String = s TextDim sfTemp As StringFormat = New StringFormat ( ) sfTemp Alignment = StringAlignment CentersfTemp LineAlignment = StringAlignment CenterDim rcText As RectangleF = rfBoundrcText Width = e Graphics DrawString ( s New Font ( Veranda ) New SolidBrush ( Color Blue ) rcText sfTemp ) e Graphics DrawRectangle ( New Pen ( New SolidBrush ( Color LightGray ) ) rfBound ) If e State = ( DrawItemState NoAccelerator Or DrawItemState Selected ) Then e Graphics FillRectangle ( New SolidBrush ( Color LightYellow ) rfBound ) e Graphics DrawString ( s New Font ( Veranda FontStyle Bold Or FontStyle Underline ) New SolidBrush ( Color Red ) rcText sfTemp ) e Graphics DrawRectangle ( New Pen ( New SolidBrush ( Color Black ) ) rfBound ) e DrawFocusRectangle ( ) End IfEnd Sub
MenuItem 的DrawItem事件处理代码之后添加下列代码 下列代码是定义MenuItem 的MeasureItem事件 在此事件中实现设定 新建 菜单项的长度和高度
Private Sub MenuItem _MeasureItem ( ByVal sender As Object ByVal e As System Windows Forms MeasureItemEventArgs ) Handles MenuItem MeasureItem e ItemWidth = 设定菜单项的宽度 e ItemHeight = 设定菜单项的高度End Sub
在上述步骤都正确完成后 本文介绍的手工绘制菜单就完成 此时单击快捷键F 运行 程序就可以得到图 所示的运行界面
六.总结
本文主要内容是介绍VB NET设计和创建菜单 其中不仅介绍了使用菜单设计器来静态设计菜单 还介绍了使用MainMenu类 MenuItem类和ContextMenu类动态创建菜单的实现方法 在动态创建时 首先要了解要创建的菜单类型 是下拉菜单 首先要创建一个MainMenu实例 是弹出菜单 首先要创建一个ContextMenu实例 然后根据菜单中的组成结构 即菜单项中的父子关系 创建出相应菜单 最后就是显示出菜单 如果是下拉菜单 指派给Form的Menu属性 如果是弹出菜单 指派给可视组件或Form的ContextMenu属性 这样动态创建菜单才能够显示出来 动态创建菜单的工作才算完成
此外还介绍了在Visual Basic Net中绘制个性化菜单的实现方法和注意事项 在绘制个性化菜单时最重要的是掌握DrawItem事件和MeasureItem事件用法 及绘制菜单时所要使用到的方法 虽然本文绘制的菜单并不美观 但你可以通过本文介绍的方法来修改 从而实现更美观 更有个性的菜单 最后请记住 在绘制菜单时 首先把菜单项的 OwnerDraw 属性设定为 True
lishixinzhi/Article/program/net/201311/15454
Q2: VB.NET是什么?怎么才能入门
所谓VB.NET就是VB7.0,现在已经到了VB8.0,你要是初学的,我建议你去买清华大学出版社的VB.NET程序设计与上机指导这本书,我刚学完挺不错的。
Q3: 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
Q4: 那里有VB.NET2005入门教程我的意思是我现在用VS2005可是用的语言是VB...请大家帮帮忙
向vb.net入门网你推荐一个电子书的网站vb.net入门网,全面vb.net入门网,希望你能找到喜欢的书
vb.net入门网的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vbnet教程、vb.net入门网的信息别忘了在本站进行查找喔。








