0

我正在使用 Visual Basic.NET,并且正在为足球裁判制作一个 Payscale 程序,您可以在其中输入您的年龄,它会告诉您您赚了多少。与经典足球相比,休闲足球向裁判支付更少的薪水。我有一个 Rec 和一个经典菜单。我这样做是为了让代码自动使用 Rec Payscale,当我单击经典菜单并输入年龄以尝试给我更新的工资时,它仍然给我 Rec Pay。我怎样才能做到这一点,当我单击该菜单然后输入年龄时,它会给我经典的工资表而不是记录工资表?

Public Class Form1

Private Sub txtanswer_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtanswer.TextChanged
    If txtanswer.Text = "U8" Then
        lblanswer.Text = "$16"
    End If
    If txtanswer.Text = "U9" Or txtanswer.Text = "U10" Then
        lblanswer.Text = "Center - $20, AR - $10"
    End If
    If txtanswer.Text = "U11" Or txtanswer.Text = "U12" Then
        lblanswer.Text = "Center - $22, AR - $12"
    End If
    If txtanswer.Text = "U13" Or txtanswer.Text = "U14" Then
        lblanswer.Text = "Center - $24, AR - $14"
    End If
    If txtanswer.Text = "U15" Or txtanswer.Text = "U16" Then
        lblanswer.Text = "Center - $26, AR - $16"
    End If
    If txtanswer.Text = "U17" Or txtanswer.Text = "U18" Then
        lblanswer.Text = "Center - $30, AR - $20"
    End If
    End Sub

 Private Sub ClassicToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClassicToolStripMenuItem.Click
    If txtanswer.Text = "U11" Or txtanswer.Text = "U12" Then
        lblanswer.Text = "Center - $25, AR - $15"
    End If
    If txtanswer.Text = "U13" Or txtanswer.Text = "U14" Then
        lblanswer.Text = "Center - $30, AR - $18"
    End If
    If txtanswer.Text = "U15" Or txtanswer.Text = "U16" Then
        lblanswer.Text = "Center - $34, AR - $20"
    End If
    If txtanswer.Text = "U17" Or txtanswer.Text = "U18" Then
        lblanswer.Text = "Center - $38, AR - $22"
    End If
End Sub
End Class
4

1 回答 1

1

最简单的方法可能是改变您对待菜单条项目的方式。菜单通常会做一些事情,您希望它保留要评估的选择。因此,将其视为单击事件中的复选框:

  ClassicToolStripMenuItem.Checked = Not ClassicToolStripMenuItem.Checked

这将切换检查状态并允许您测试是否在代码中检查了菜单项。

编辑

如果您像复选框一样使用 MenuItem,您可以:

If ClassicToolStripMenuItem.Checked Then
   ' do classic calcs
   ... copy code from the menu click event
Else
   ' it is NOT checked
   ...use the code already in text changed
End If

提示:

  • 考虑学习 SELECT CASE

  • 当我输入“U11”时,“U”和“U1”不匹配,所以前面的结果显示。考虑不同的输入方法可能会更好。

  • 最后,“u11”不会匹配并发布结果,因为“U11”<>“u11”。您可能想要更改测试。(看String方法)。

于 2013-09-22T00:40:32.977 回答