Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何检查是否已填写所有字段_C#_Winforms_Visual Studio 2010 - Fatal编程技术网

C# 如何检查是否已填写所有字段

C# 如何检查是否已填写所有字段,c#,winforms,visual-studio-2010,C#,Winforms,Visual Studio 2010,如何检查某些字段是否不完整 我希望这样,每当有人单击我的“添加”按钮时,如果必填字段没有正确填写,就会出现一个消息框。使用a,或者如果输入文本长度为0,则只需检查输入文本长度即可抛出一条消息 If (myTextBox.Text.Length == 0) { //throw up message box MessageBox.Show("You forgot to fill in this field!"); return; } 使用,或者只需检查输入文本长度(如果为0)

如何检查某些字段是否不完整

我希望这样,每当有人单击我的“添加”按钮时,如果必填字段没有正确填写,就会出现一个消息框。

使用a,或者如果输入文本长度为0,则只需检查输入文本长度即可抛出一条消息

If (myTextBox.Text.Length == 0)
 {
   //throw up message box
   MessageBox.Show("You forgot to fill in this field!");
   return;
 }
使用,或者只需检查输入文本长度(如果为0)即可抛出消息

If (myTextBox.Text.Length == 0)
 {
   //throw up message box
   MessageBox.Show("You forgot to fill in this field!");
   return;
 }

在“添加”按钮的事件处理程序中,只需检查“字段”是否已填写,如果未填写,请不要继续:

void buttonAdd_Click(object sender, EventArgs e)
{
    if (string.IsNullOrWhiteSpace(textBoxField.Text))
    {
         // Show message?
         MessageBox.Show(....);

         return; // Don't process
    }

    // Field has a value, do your thing here...

}

在“添加”按钮的事件处理程序中,只需检查“字段”是否已填写,如果未填写,请不要继续:

void buttonAdd_Click(object sender, EventArgs e)
{
    if (string.IsNullOrWhiteSpace(textBoxField.Text))
    {
         // Show message?
         MessageBox.Show(....);

         return; // Don't process
    }

    // Field has a value, do your thing here...

}

你不能在添加按钮的事件处理程序中这样做?作为旁注-在这个论坛中没有必要写这样的东西
请有人回答这个问题。就这个!!我保证
@seldon-我不认为这是一个他/她不能回答的问题,而是如何回答的问题。你的问题到底是什么?我有一种感觉,你请求我们回答这个问题的原因是因为你过去的问题因为含糊不清而被关闭。你不能在添加按钮的事件处理程序中这样做?作为旁注-在这个论坛中没有必要写这样的
请有人回答这个问题。就这个!!我保证
@seldon-我不认为这是一个他/她不能回答的问题,而是如何回答的问题。你的问题到底是什么?我有一种感觉,你请求我们回答这个问题的原因是因为你过去的问题已经结束,因为它们是模糊的。谢谢!这个片段真的很有用!谢谢这个片段真的很有用!