×

VB.Net基本教程

VB.Net 环境设置VB.Net 程序结构VB.Net 基本语法VB.Net 数据类型VB.Net 变量VB.Net 常数和枚举VB.Net 修饰符VB.Net 声明VB.Net 指令VB.Net 运算符VB.Net 决策VB.Net 循环VB.Net 字符串VB.Net 日期和时间VB.Net 数组VB.Net 集合VB.Net 函数VB.Net Sub过程(子程序)VB.Net 类与对象VB.Net 异常处理VB.Net 文件处理VB.Net 基本控制VB.Net 对话框VB.Net 高级表单VB.Net 事件处理

VB.Net 高级教程

VB.Net 正则表达式VB.Net 数据库访问VB.Net Excel工作表VB.Net 发送邮件VB.Net XML处理VB.Net Web编程

VB.Net 有用的资源

VB.Net 有用资源

VB.Net 基本控制


对象是通过使用工具箱控件在Visual Basic窗体上创建的一种用户界面元素。 事实上,在Visual Basic中,表单本身是一个对象。 每个Visual Basic控件由三个重要元素组成:

  • Properties:描述对象的属性,

  • Methods:方法导致对象做某事,

  • Events:事件是当对象做某事时发生的事情。


控制属性

所有Visual Basic对象可以通过设置其属性来移动,调整大小或自定义。 属性是由Visual Basic对象(例如Caption或Fore Color)持有的值或特性。

属性可以在设计时通过使用属性窗口或在运行时通过使用程序代码中的语句来设置。

Object. Property = Value

  • Object is the name of the object you're customizing.  Object是您要定制的对象的名称。

  • Property is the characteristic you want to change.  属性是您要更改的特性。

  • Value is the new property setting.  Value是新的属性设置。


例如,

Form1.Caption = "Hello"

您可以使用属性窗口设置任何窗体属性。 大多数属性可以在应用程序执行期间设置或读取。 您可以参考Microsoft文档中与应用于它们的不同控件和限制相关的属性的完整列表。


控制方法

方法是作为类的成员创建的过程,它们使对象做某事。 方法用于访问或操纵对象或变量的特性。 您将在类中使用的主要有两类方法:


1、如果您使用的工具箱提供的控件之一,您可以调用其任何公共方法。 这种方法的要求取决于所使用的类。

2、如果没有现有方法可以执行所需的任务,则可以向类添加一个方法。


例如,MessageBox控件有一个名为Show的方法,它在下面的代码片段中调用:

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
	Handles Button1.Click
        MessageBox.Show("Hello, World")
    End Sub
End Class


控制事件

事件是通知应用程序已发生重要事件的信号。 例如,当用户单击表单上的控件时,表单可以引发Click事件并调用处理事件的过程。 有与窗体相关联的各种类型的事件,如点击,双击,关闭,加载,调整大小等。

以下是表单Load事件处理程序子例程的默认结构。 您可以通过双击代码来查看此代码,这将为您提供与表单控件相关联的所有事件的完整列表:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 'event handler code goes here
End Sub


这里,Handles MyBase.Load表示Form1_Load()子例程处理Load事件。 类似的方式,你可以检查存根代码点击,双击。 如果你想初始化一些变量,如属性等,那么你将这样的代码保存在Form1_Load()子程序中。 这里,重要的一点是事件处理程序的名称,默认情况下是Form1_Load,但您可以根据您在应用程序编程中使用的命名约定更改此名称。


基本控制

VB.Net提供了各种各样的控件,帮助您创建丰富的用户界面。 所有这些控制的功能在相应的控制类中定义。 控制类在System.Windows.Forms命名空间中定义。

下表列出了一些常用的控件:

S.N. 小部件和说明
1

Forms 形式

The container for all the controls that make up the user interface.

用于构成用户界面的所有控件的容器。

2

TextBox 文本框

It represents a Windows text box control.

它代表一个Windows文本框控件。

3

Label 标签

It represents a standard Windows label.

它代表一个标准的Windows标签。

4

Button 按钮

It represents a Windows button control.

它代表一个Windows按钮控件。

5

ListBox  列表框

It represents a Windows control to display a list of items.

它代表一个显示项目列表的Windows控件。

6

ComboBox 组合框

It represents a Windows combo box control.

它代表一个Windows组合框控件。

7

RadioButton 单选按钮

It enables the user to select a single option from a group of choices when paired with other RadioButton controls.

它使用户能够在与其他RadioButton控件配对时从一组选项中选择一个选项。

8

CheckBox 复选框

It represents a Windows CheckBox.

它代表一个Windows复选框。

9

PictureBox 图片框

It represents a Windows picture box control for displaying an image.

它表示用于显示图像的Windows画面框控件。

10

ProgressBar 进度条

It represents a Windows progress bar control.

它代表一个Windows进度条控件。

11

ScrollBar 滚动条

It Implements the basic functionality of a scroll bar control.

它实现滚动条控件的基本功能。

12

DateTimePicker 日期输入框

It represents a Windows control that allows the user to select a date and a time and to display the date and time with a specified format.

它代表一个Windows控件,允许用户选择日期和时间,并以指定的格式显示日期和时间。

13

TreeView 树状图

It displays a hierarchical collection of labeled items, each represented by a TreeNode.

它显示标签项的分层集合,每个由树节点表示。

14

ListView 列表显示

It represents a Windows list view control, which displays a collection of items that can be displayed using one of four different views.

它代表一个Windows列表视图控件,它显示可以使用四个不同视图之一显示的项目集合。



分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)