主题:动态生成控件的问题
各位我刚学Vb.net,对于动态生成控件不甚明白,望各位指教。
我想完成生成一个CheckBox的功能,但是如下代码为何不能得到一个动态生成的CheckBox。
代码如下:
Public Class Form1
Inherits System.Windows.Forms.Form
" Windows Form Designer generated code "
Private chk As Windows.Forms.CheckBox
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
chk = New CheckBox
Me.chk.Location = New System.Drawing.Point(192, 128)
Me.chk.Name = "CheckBox1"
Me.chk.Size = New System.Drawing.Size(56, 32)
Me.chk.TabIndex = 0
Me.chk.Text = "CheckBox1"
End Sub
End Class
我想完成生成一个CheckBox的功能,但是如下代码为何不能得到一个动态生成的CheckBox。
代码如下:
Public Class Form1
Inherits System.Windows.Forms.Form
" Windows Form Designer generated code "
Private chk As Windows.Forms.CheckBox
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
chk = New CheckBox
Me.chk.Location = New System.Drawing.Point(192, 128)
Me.chk.Name = "CheckBox1"
Me.chk.Size = New System.Drawing.Size(56, 32)
Me.chk.TabIndex = 0
Me.chk.Text = "CheckBox1"
End Sub
End Class