簡體   English   中英

單擊一次按鈕后,如何使我的按鈕再次通過代碼?

[英]How do I get my button to go through it's code again after clicking it once already?

我的應用程序中有一個按鈕,即提交按鈕。 應該使用此按鈕來驗證在表格中輸入的卡號。

第三次輸入錯誤后,應用程序應結束。 所有必需的代碼都在這里。 但是,當我運行它並故意在其中放置錯誤時,將顯示消息框,但是當我修復文本框並再次單擊提交按鈕時,什么也沒有發生。

我如何才能使按鈕重新工作?

private void submitOrderButton_Click(object sender, EventArgs e)
{
    counter += 1;

    string cardFirstFour = verifyTextBox.Text;

    if (counter <= 3)
    {
        if (verifyTextBox.TextLength == 1298 || verifyTextBox.TextLength == 12765 || 
            verifyTextBox.TextLength == 4512 || verifyTextBox.TextLength == 4567 && 
            verifyTextBox.TextLength == 8901 || verifyTextBox.TextLength == 8933)
        { 
            if (verifyTextBox.TextLength == 4 || cardTextBox2.TextLength == 4 || 
                cardTextBox3.TextLength == 4 || cardTextBox4.TextLength == 4)
            { 
                if (securityCodetextBox.TextLength == 3)
                { 
                    if (DateTime.Now.Month < monthNumericUpDown.Value && 
                        DateTime.Now.Year < yearNumericUpDown.Value)
                    {
                        Hide();
                        confirmation.ShowDialog();
                    }
                    else if (counter > 3)
                    {
                        this.Hide();
                        MessageBox.Show("Invalid card info: Too many wrong entries. Order canceled", "Invalid Entry",
                               MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Invalid card info: Check your card and try again.", "Invalid Entry",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
    }
}

我不認為你的if條件是正確的。

你有這個

if (counter <= 3) {
    ...
    else if (counter > 3)
    ...
}

因此, else if以上條件不能滿足else if條件。 您應該像這樣構造它:

if (counter <= 3) {

} else if (counter > 3) {

}

另外,我將更具體一些,將counter重命名為invalidCounter並且僅在信息無效時遞增counter ,而不是在每次單擊按鈕時遞增counter

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM