The syntax is wrong. Either way it has an easier way to do what you want:
private void Botão_Click(object sender, EventArgs e) {
PBox.Visible = !Pbox.Visible;
}
I've placed it on GitHub for future reference.
If it were to write the question form it should look like this:
if (Pbox.Visible) {
Pbox.Hide();
} else {
Pbox.Show();
}
The methods Hide()
and Show()
do not return anything so they can not be used as a condition of if
that a boolean expects. To find out if the control is visible use the Visible
. It is not necessary to use a condition in else
since this property can only return two values, or it is true, or false, if it is true executes the block of if
, otherwise it will execute the block of else
, independent of anything else. Even if it were the case of using a condition, it could only with a else if
.