Visual Basic动态文本框

时间:2018-11-07 13:48:04

标签: vb.net

应用和代码

Private Sub PriceBox_Click(sender As Object, e As EventArgs) Handles PriceBox.Click
    If CmbSize.SelectedIndex = 0 Then
        PriceBox.Text = "£30"
    ElseIf CmbSize.SelectedIndex = 1 Then
        PriceBox.Text = "£40"
    ElseIf CmbSize.SelectedIndex = 2 Then
        PriceBox.Text = "£50"
    End If

End Sub

此代码有效,但仅在单击时有效,选择组合框索引后,我需要使用它来自动更改

3 个答案:

答案 0 :(得分:1)

如果只希望用户更改索引而不是程序更改,请使用

SelectionChangeCommitted

https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.combobox.selectionchangecommitted?view=netframework-4.7.2

答案 1 :(得分:0)

答案 2 :(得分:0)

组合框有SelectedIndexChanged-event,您可以使用:

Private Sub CmbSize_Changed(sender As Object, e As EventArgs) Handles CmbSize.SelectedIndexChanged   

End Sub