求助 vb.net 动态生成控件问题?
我想在FORM中动态生成几个checkbox的控件并定义他的text,且排位。求例子? VB.NET 控件 动态
[解决办法]
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim nLeft As Double = 0, nTop As Double = 0
Dim nWidth As Double = 114, nHeight As Double = 16
For i As Integer = 1 To 20
Dim a As New CheckBox
a.Text = "第" & i.ToString & "个CheckBox"
Me.Controls.Add(a)
a.Visible = True
If a.Width + nLeft > Me.Width Then
nLeft = 0 : nTop = nTop + nHeight + 10
End If
a.SetBounds(nLeft, nTop, nWidth, nHeight)
nLeft = nLeft + a.Width + 10
'nTop = a.Top
AddHandler a.Click, AddressOf aaa
Next
End Sub
Private Sub aaa(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox(sender.text & "被你选中了")
End Sub
End Class