Search code examples
c#winformsif-statementvisible

Check if a label has visible property to true.c# winforms


How to check if a label is visible?This is not working...

   if(labelFS.Visible = false)
        {do sth}
   else//labelFS.Visible = true
        {do other}

solved


Solution

  • Use == to compare two values, not the assignment operator (a single =).

    By using a single =, you're actually setting the value of labelFS.Visible to False, which hides it.

    (There's also no need to type out true and false .)

    if (labelFS.Visible)
        // do something
    else
        // do something else
    

    I'd suggest reading up on the difference. Here's a start...