我正在嘗試創建車牌生成器。無論何時運行,它都會創建一個隨機車牌。但是,如果沒有輸入姓名,我需要停止程序繼續生成車牌,就像暫停它,直到輸入所有信息。我知道我需要一個返回函數,但我不知道如何使用它。以下是目前爲止的代碼:如何停止運行程序
if (string.IsNullOrWhiteSpace(NameTextBox.Text))
{
userAnswer = MessageBox.Show("Please enter a valid name for the motorist", "Error Message", MessageBoxButtons.YesNo);
if (userAnswer == DialogResult.No)
{
Application.Exit();
}
sb.Append(currentTime);
ActivityrichTextBox.Text = ActivityrichTextBox.Text + sb.ToString();
sb.Clear();
sb.Append("**Error** failed to enter a valid name");
ActivityrichTextBox.Text = ActivityrichTextBox.Text + " " + sb.ToString() + Environment.NewLine;
sb.Clear();
我知道如果沒有輸入名稱,它會在某處停止。
添加'YesNo'對話框在這裏並不直觀。把它做成一個「好」的盒子。 – sircapsalot
'Progam:'「請輸入一個名字。」 '用戶:'「不!」 = P –
您也許還想使用這個組件: http://msdn.microsoft.com/en-us/library/system.windows.forms.errorprovider.aspx 有很多使用它的例子。 – FelProNet