我是VB6的新手。我有一个名为“combo”的comboBox控件。我需要在点击事件发生时显示所选组合项的值。 Hovewer显示MsgBox加载表单
Private Sub combo_Click()
label_1.Caption = combo.Text
MsgBox combo.Text
End Sub
Private Sub combo_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
Private Sub Command1_Click()
Dim nombre1 As String
Dim apellido1 As String
nombre1 = nombre.Text
apellido1 = apellido.Text
resultado.Text = nombre1 + " " + apellido1
End Sub
Private Sub Form_Load()
combo.AddItem ("fernando")
combo.AddItem ("juan")
combo.AddItem ("pepep")
combo.AddItem ("jose")
combo.AddItem ("luis")
combo.ListIndex = 0
End Sub
答案 0 :(得分:3)
即使没有点击也会发生点击事件。当你把combo.ListIndex = 0时,它出现在Form Load中。抑制这一行,表单加载时不会出现msgbox。但是如果你想在表单加载时分配一个默认值,那么你可以使用flag。
Private Ignore As Boolean
Private Sub combo_Click()
Label_1.Caption = Combo.Text
If Ignore Then
Ignore = False
Else
MsgBox Combo.Text
End If
End Sub
Private Sub Command1_Click()
Dim nombre1 As String
Dim apellido1 As String
nombre1 = nombre.Text
apellido1 = apellido.Text
resultado.Text = nombre1 + " " + apellido1
End Sub
Private Sub Form_Load()
Combo.AddItem ("fernando")
Combo.AddItem ("juan")
Combo.AddItem ("pepep")
Combo.AddItem ("jose")
Combo.AddItem ("luis")
Ignore = True
Combo.ListIndex = 0
End Sub