我正在 Visual Basic 2010 Express Edition 处理库存.我不知道库存所需的字段数。我希望我可以在程序中使用 for 循环添加文本框/复选框/按钮。有没有办法在不使用工具箱的情况下向表单添加控件?
我可以通过在程序中实例化它们来添加控件吗?
最佳答案
是的。
Private Sub MyForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim MyTextbox as New Textbox
With MyTextbox
.Size = New Size(100,20)
.Location = New Point(20,20)
End With
AddHandler MyTextbox.TextChanged, AddressOf MyTextbox_Changed
Me.Controls.Add(MyTextbox)
'Without a help environment for an intelli sense substitution
'the address name and the methods name
'cannot be wrote in exchange for each other.
'Until an equality operation is prior for an exchange i have to work
'on an as is base substituted.
End Sub
Friend Sub MyTextbox_Changed(sender as Object, e as EventArgs)
'Write code here.
End Sub
关于vb.net - 如何以编程方式向 VB.NET 中的窗体添加控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11312239/