1
嗨,我还是相当新的VB.NET ... 我有以下代码的窗体有一个按钮(Button1)。 当我按下此按钮时,它会添加一些带有某些值的组合框(每次按下按钮时都会添加一个新组合框)。 如何设置和事件,以便当组合框更改时,文本框将出现在它的右侧? 我基本上是根据每个组合框中选择的内容来查看具有不同的行为。当我通过VB.NET代码插入组合框时,如何让它有事件?
Public Class frmEditor
Private Const rowHeight = 25
Dim datarows() As Action
Dim currentrow As Integer
Dim starttop As Integer
Private Sub frmEditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
currentrow = 1
starttop = 20
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CreateRow()
currentrow = currentrow + 1
starttop = starttop + rowHeight
End Sub
Private Sub CreateRow()
Dim newrow As Action = New Action()
ReDim Preserve datarows(currentrow)
datarows(currentrow) = newrow
datarows(currentrow).newAction(15, starttop, currentrow)
End Sub
End Class
Public Class Action
Private cbo As New ComboBox()
Public Sub newAction(ByVal xleft As Integer, ByVal ytop As Integer, ByVal nrow As Integer)
cbo.Top = ytop
cbo.Left = xleft
cbo.Visible = True
cbo.Items.Add("Test1")
cbo.Items.Add("Test2")
frmEditor.Controls.Add(cbo)
End Sub
End Class
嗯是的,我现在想通了。谢谢。 我添加了: AddHandler cbo.SelectedValueChanged,AddressOf ChangeCombo 到newAction方法并创建了一个名为ChangeCombo的新方法 – 2010-02-13 01:47:57
太棒了...很高兴工作。 – 2010-02-13 17:51:12