如何使用影响复选框的单选按钮

时间:2017-12-11 05:08:17

标签: vb.net visual-studio radio-button visual-studio-2017

您好我想知道是否有人可以帮助告诉我我做错了什么。因此,对于我的作业,我需要这样做,以便每当您在表单左侧选择一个特定的单选按钮时,它会更改可用的选项,以便在表单右侧添加项目。对于我的任务,它说要做一个事件处理程序来执行此操作。以下是作业

的确切行

"编写一个事件处理程序,用于更改为Add-ons组框显示的文本以及当用户选择其他主菜单时的三个复选框。此事件处理程序还应删除加载项中的复选标记并清除订单总计。测试应用程序以确保其正常工作。"

我无法弄清楚为什么我的代码无法正常工作。我现在尝试了一些不同的东西。任何帮助将非常感激。下面是参考表格的截图,以及我的代码。

https://imgur.com/a/l2PPG

    Private Sub ClearTexts()
    txtOrderTotal.Text = ""
    txtSubTotal.Text = ""
    txtTax.Text = ""
End Sub
Private Sub ClearChecks()
    chbBox1.Checked = False
    chbBox2.Checked = False
    chbBox3.Checked = False
End Sub


Private Sub grpAddon_TextChanged(sender As Object, e As EventArgs) Handles grpAddon.TextChanged

    If rbHamburger.Checked Then
        chbBox1.Text = "Lettuce, tomato, and onions"
        chbBox2.Text = "Ketchup, mustard, and mayo"
        chbBox3.Text = "French fries"
    ElseIf rbPizza.Checked Then
        chbBox1.Text = "Pepperoni"
        chbBox2.Text = "Sausage"
        chbBox3.Text = "Olives"
    ElseIf rbSalad.Checked Then
        chbBox1.Text = "Croutons"
        chbBox2.Text = "Bacon Bits"
        chbBox3.Text = "Bread Sticks"
    End If

    ClearTexts()
    ClearChecks()
End Sub

1 个答案:

答案 0 :(得分:1)

看起来你的目标是错误的事件。您的子例程应该处理RadioButtons的CheckedChanged事件,而不是GroupBox的TextChanged事件。

Private Sub grpAddon_RadioChanged(sender As Object, e As EventArgs) Handles rbHamburger.CheckedChanged, rbPizza.CheckedChanged, rbSalad.CheckedChanged

    chbBox1.Checked = False
    chbBox2.Checked = False
    chbBox3.Checked = False

    If rbHamburger.Checked Then
        chbBox1.Text = "Lettuce, tomato, and onions"
        chbBox2.Text = "Ketchup, mustard, and mayo"
        chbBox3.Text = "French fries"
    ElseIf rbPizza.Checked Then
        chbBox1.Text = "Pepperoni"
        chbBox2.Text = "Sausage"
        chbBox3.Text = "Olives"
    ElseIf rbSalad.Checked Then
        chbBox1.Text = "Croutons"
        chbBox2.Text = "Bacon Bits"
        chbBox3.Text = "Bread Sticks"
    End If

End Sub