日期:2012-10-25  浏览次数:20411 次

因为考虑到有部分初学者VB6没有用过,所以我在源码中对每一句代码都进行了注释。
首先如下添加控件:


添加三个button控件,写代码如下:

Imports System.ComponentModel '引用 族名 System.ComponentModel

Imports System.Drawing '引用族名 System.Drawing

Imports System.WinForms '引用族名 System.WinForms

'引用族名的目的是在调用他的子类时不需要写出族名,如system.drawing.color写成color

Public Class Form1

Inherits System.WinForms.Form ' Inherits是从已有的一个类继承,得到这个类已定义的方法



Public Sub New()

MyBase.New() 'mybase是指代父类 mybase.new是调用父类的new过程,new是新建一个对象,对象是存在内存的,类是并不存在内存的



Form1 = Me '这样,下面的me关键字 就被认定为form1





InitializeComponent() '这下面的代码是在新建一个form1的实例时执行的初始化动作

Call me_load() '这是自定义的一个子过程



End Sub



'Form overrides dispose to clean up the component list.

Overrides Public Sub Dispose()

AxMMControl1.Command = "close" '关闭声音资源,这个代码一定要放在dispose过程的前面

MyBase.Dispose() 'dispose是清除对象

components.Dispose() '清空组件

End Sub



'下面的代码是对属性的描述,是系统自已生成的,不要随意修改

#Region " Windows Form Designer generated code "



'Required by the Windows Form Designer

Private components As System.ComponentModel.Container

Private WithEvents Button3 As System.WinForms.Button

Private WithEvents Button2 As System.WinForms.Button

Private WithEvents Button1 As System.WinForms.Button

Private WithEvents AxMMControl1 As AxMCI.AxMMControl



Dim WithEvents Form1 As System.WinForms.Form



'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Private Sub InitializeComponent()

Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))



Me.components = New System.ComponentModel.Container()

Me.Button1 = New System.WinForms.Button()

Me.AxMMControl1 = New AxMCI.AxMMControl()

Me.Button3 = New System.WinForms.Button()

Me.Button2 = New System.WinForms.Button()



AxMMControl1.BeginInit()



'@design Me.TrayHeight = 0

'@design Me.TrayLargeIcon = False

'@design Me.TrayAutoArrange = True

Button1.Location = New System.Drawing.Point(8, 8)

Button1.Size = New System.Drawing.Size(80, 32)

Button1.TabIndex = 1

Button1.Text = "Button1"



AxMMControl1.OcxState = CType(resources.GetObject("AxMMControl1.OcxState"), System.WinForms.AxHost.State)

AxMMControl1.TabIndex = 0

AxMMControl1.Size = New System.Drawing.Size(236, 33)

AxMMControl1.Location = New System.Drawing.Point(32, 56)



Button3.Location = New System.Drawing.Point(208, 8)

Button3.Size = New System.Drawing.Size(80, 32)

Button3.TabIndex = 3

Button3.Text = "Button3"



Button2.Location = New System.Drawing.Point(104, 8)

Button2.Size = New System.Drawing.Size(88, 32)

Button2.TabIndex = 2

Button2.Text = "Button2"

Me.Text = "Form1"

Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)

Me.ClientSize = New System.Drawing.Size(296,