
正文
初学者vb.net 初学者练字用什么笔
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
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
相关问答
Q1: VB.net编程初学者出现“索引超出了数组界限”问题,望各位高手解答。
在VB里,"平均分"(pingjunfen), 这是数组的调用方法,当然会报错了
这样改吧:
Dim xingming As String
Dim yuwen As Short
Dim shuxue As Short
Dim yingyu As Short
Dim zonghe As Short
Dim pingjunfen As Short
xingming = InputBox("输入姓名", "输入名字吧")
yuwen = InputBox("输入语文成绩", vbOKOnly)
shuxue = InputBox("输入数学成绩", vbOKOnly)
yingyu = InputBox("输入英语成绩", vbOKOnly)
zonghe = yuwen + shuxue + yingyu
pingjunfen = zonghe / 3
MsgBox("平均分:" pingjunfen, [vbOKOnly])
Q2: VB.NET初学者大家帮帮忙
想改变按钮的样子吗初学者vb.net,那实际上不是按钮控件初学者vb.net,那个是图片框鼠标放到上面就换一张图片初学者vb.net,左键单击的时候就又换一张图片初学者vb.net,才会出现的这种效果。
Q3: 求助,初学者想问VB.NET,怎么输入一维列矩阵或者一维行矩阵怎么转置成一维列矩阵?谢谢了!
在程序设计语言里,用二维数组来保存矩阵的值。
一维列矩阵,就是由:若干行、一列组成的二维数组。
一维行矩阵,就是由:一行、若干列组成的二维数组。
比如一维列矩阵,的输入:
dim a(10,1) as integer '10行,1列
dim i as integer
for i = 1 to 10
a(i,1) = inputbox("")
next i
Q4: 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
Q5: vb.net和java哪个更适合初学者
如果初学者vb.net你要先学.net初学者vb.net的话初学者vb.net,你要学初学者vb.net的东西很多,包括微软整个的.net框架都要学,而且你还得学win32编程的一些基础。
学java的话,只要学习java基础,和一些jdk类包,另外再有一些java的编程思想就很好了。
另外,虽然两个都是面向对象的,但是java的面向对象更纯粹一些,要想更深刻的理解面向对象的编程方式,建议你先学java。
等java学的已经差不多的时候,你可以学。.net。因为java毕竟不能直接对内存操作,让你丧失了对“底层”管理的能力,学习微软的东西可以让你对底层的操作有一些认识,但是.net好像还是很脱离底层的。
如果你是要做网页的话,除了java和.net之外,还有一个开源的项目,也就是所谓的PHP+Apache+MySQL。PHP很容易上手,跟Perl结合,也是很不错的一条路。
自己拿捏:)。祝好运!
关于初学者vb.net和初学者练字用什么笔的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







