在这个区域里,你会看到几个关键的元素:
一个窗体的构造器(constructor)(a Sub New())
一个释放(Dispose)程序
窗体中所有控件的声明
一个名为InitializeComponent的子程序
构造器和释放程序与VB6中的Class_Initialize和Class_Terminate事件基本等效。设计器所产生的代码的实质是其他两部分-控件声明的列表和InitializeComponent程序。看一下创建这个简单的例子所产生的代码。如下:
'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. Friend WithEvents Button1 As System.Windows.Forms.Button <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.Button1 = New System.Windows.Forms.Button Me.SuspendLayout() ' 'Button1
' Me.Button1.Location = New System.Drawing.Point(96, 88) Me.Button1.Name = "Button1" Me.Button1.TabIndex = 0 Me.Button1.Text = "Button1" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.Add(Me.Button1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub 从上面的代码中的12到15行,你可以看到是用来设置按钮的大小等属性。
假若你增加一些你自己的代码,即使是一些简单的代码,将会产生意想不到的结果。
在这儿,我们只增加一行简单的代码如下:
' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(96, 88) Me.Button1.Name = "Button1" Debug.WriteLine("Testing!") Me.Button1.TabIndex = 0 Me.Button1.Text = "Button1"
|