我正在制作一个应用程序来计算您按下按钮的次数,但目前我的编码性能非常糟糕,我想在点击 5 次时立即禁用按钮,但目前无法正常工作,所以我在想,如果可能的话,你们是否可以帮我改进它。
这是代码
public partial class MainPage : PhoneApplicationPage
{
private int count = 10;
private int tap = 0;
DispatcherTimer timerCountDown = new DispatcherTimer();
public MainPage()
{
InitializeComponent();
timerCountDown.Interval = new TimeSpan(0, 0, 1);
timerCountDown.Tick += new EventHandler(timerCountDown_Tick);
timerCountDown.Start();
}
//buttom counts
private void Button_Click(object sender, RoutedEventArgs e)
{
counter();
}
//timer
void timerCountDown_Tick(object sender, EventArgs e)
{
timer();
level();
}
//time remaning
private void timer()
{
txtTimerCount.Text = "Left " + count.ToString();
if (count > 0)
count--;
else
txtTimerCount.Text = "Times Up";
if (txtTimerCount.Text == "Times Up")
btntap.IsEnabled = false;
}
//counts clicks
private void counter()
{
tap++;
txtTimerTap.Text = "Tap Count: " + tap.ToString();
}
//level1
private void level()
{
if (tap == 5)
txtcomplet.Text = "Well done level completed";
if
(tap == 5)
btntap.IsEnabled = false;
}