Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 784
  • 1.1k
  • 55.3k

Window Form Validation Error

Oct 13 2023 11:24 PM

Hello Team,

Am developing this c# window form application, and i introduce textbox validation in the class to give warning when the user try to insert empty textbox and the code give me this error, 

 Error    1    'System.Windows.Forms.TextBox' does not contain a definition for 'BorderColor' and no extension method 'BorderColor' accepting a first argument of type 'System.Windows.Forms.TextBox' could be found (are you missing a using directive or an assembly reference?)    c:\users\nyanu\onedrive\documents\visual studio 2013\projects\windowsformsapplicationpos\windowsformsapplicationpos\mainclass.cs    189    23    WindowsFormsApplicationPOS

 

public static bool Validation(Form F)
{
    bool isValid = false;

    int count = 0;
    foreach(Control c in F.Controls)
    {
        // using tag of the control to check if we want to validate it or not
        if (Convert.ToString(c.Tag) != "" && Convert.ToString(c.Tag) != null)
        {
            if (c is System.Windows.Forms.TextBox)
            {
                System.Windows.Forms.TextBox t = (System.Windows.Forms.TextBox)c;
                if(t.Text.Trim()=="")
                {

                    t.BorderColor = Color.Red;
                    t.FocusedState.BorderColor = Color.Red;
                    t.HoverState.BorderColor = Color.Red;
                    count++;
                    
                }
                else
                {
                    t.BorderColor = Color.FromArgb(213, 218, 223);
                    t.FocusedState.BorderColor = Color.FromArgb(95, 61, 204);
                    t.Hover.BorderColor = Color.FromArgb(95, 61, 204);
                }
            }
        }
        if (count == 0)
        {
            isValid = true;
        }
        else
        {
            isValid = false;
        }
    }
    return isValid;
}
    }   
}


Answers (4)