动态创建命令按钮 [英] Creating Command Button Dynamically
问题描述
我正在开发一个销售点系统,我想将商品类别作为命令按钮动态地加载到表单上.该表单将分为两部分.类别部分和项目部分.当我单击类别命令按钮时.它将动态加载选择类别下的项目作为命令按钮.
这是触摸屏销售点.请协助.
Hi am Developiong a Point of sale system, i want to load item category dynamically on a form as command buttons.the form will be divided into two sections. the category Section and the items Section. when i click the category command button. it will dynamically load the items under the select category as command buttons.
it is a touch screen point of sale. please assist.
推荐答案
出了什么问题?你在哪里困?
试试类似的东西:
What is the problem? Where are you stuck?
Try something like:
For x As Integer = 0 to buttonCount - 1
Dim newButton as Button
newButton = New Button()
With newButton
.Name = "Category" & x.ToString & "Button"
.Text = "Category " & x.ToString
AddHandler newButton.Click, AddressOf myButtonClickEvent
''You will need to position the buttons as well...
Form1.Controls.Add(newButton)
End With
Next x
并创建事件处理程序以拦截您的按钮单击事件:
And create the eventhandler to intercept your button click events:
Public Sub myButtonClickEvent(Byval Sender as Object, Byval e as System.EventArgs)
MsgBox DirectCast(sender, Button).Name & " Clicked"
End Sub
所有这些都写在我的头上,所以您可能需要做一些调整...
All this written off the top of my head, so you will probably need to do a few adjustments...
这篇关于动态创建命令按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!