ID: 4001 - Validar campos ( TextBox ) vacíos en un Windows Form
Posted by layonman98 on Sun Mar 07 15:55:36 UTC 2010. Language csharp

using System.Windows.Forms;
using System.Drawing;

public static bool HasEmptyFields( Control.ControlCollection container )
{
  var filledFiels    = 0;
  var textboxCount   = 0;
  foreach( Control c in container )
  {
    if( typeof( TextBox ) == c.GetType() )
    {
      textboxCount++;
      var textbox = ( TextBox ) c;
      if( string.Equals( "", textbox.Text ) )
      {
        textbox.BackColor = Color.PapayaWhip;
      }
      else
      {
        textbox.BackColor = Color.White;
        filledFiels++;
      }
    }
  }
  if( filledFiels < textboxCount )
    return true;
  else
    return false;
}