I want to be able to set any label's visibility to true or false with a method. I have this code:
private void Change_Visible(Label toBeChanged)
{
if (toBeChanged.Visible == false)
{
toBeChanged.Visible = true;
}
else
{
toBeChanged.Visible = false;
}
toBeChanged.Refresh();
}
I call to this code with:
Change_Visible(myLabel);
//
// Do other things
//
Change_Visible(myLabel);
In my specific example, myLabel is set to not be visible at the load of my form. After the first call to Change_Visible it becomes visible, but after the second call to Change_Visible nothing happens. Can you help me make it disappear?
I have already tried some other logics looking for a solution - for example:
private void Change_Visible(Label toBeChanged)
{
if (toBeChanged.Visible == false)
{
toBeChanged.Visible = true;
toBeChanged.Refresh();
return;
}
if (toBeChanged.Visible == true)
{
toBeChanged.Visible = false;
toBeChanged.Refresh();
return;
}
}
I have not come to any conclusions. I am learning C# by myself and started just a few weeks ago, so maybe I am missing something obvious. Thanks for your help!