我是visual basic的新手,我很难在我的标签显示中显示itembox值。有任何想法吗?
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'fill the list box with values
lstNames.Items.Add("Smith, Joe")
lstNames.Items.Add("Jones, Mary")
lstNames.Items.Add("Adkari, Joel")
lstNames.Items.Add("Lin, Sue")
lstNames.Items.Add("Li, Vicky")
lstNames.SelectedIndex = 0
End Sub
Private Sub MainForm_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
Select Case (lstNames.SelectedIndex)
Case 0
lblDisplay.Text = "3388"
Case 1
lblDisplay.Text = "3356"
Case 2
lblDisplay.Text = "2487"
Case 3
lblDisplay.Text = "1111"
Case 4
lblDisplay.Text = "2222"
End Select
End Sub
答案 0 :(得分:1)
我尝试将代码从MainForm.MouseClick事件移动到lstNames.ItemSelected
在设计视图中双击lstNames控件,默认情况下会为您创建此事件。