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