Omarrrio Omarrrio - 3 months ago 11
C# Question

Changing a Controls Visible Proprety doesn't redraw the Control

i can't get the control visible property to change accordingly to my set value in code, and it looks ugly:

htmlLabel1.Visible = false;
htmlLabel1.Update();
htmlLabel2.Visible = true;
htmlLabel2.Update();
path = s;
if (Path.GetExtension(s) == ".iso")
{
check = CalculateChecksum(s);
}


This is what it looks like:
enter image description here

Are there any alternatives to
Update()
that i can use to force redraw of the control ? (The control i am using is the HTMLLabel btw)

Answer

Use

htmlLabel2.Invalidate();

The Invalidate() method will cause the controls Paint event to fire (forcing the control to be redrawn).


MSDN Ref: Control.Invalidate Method()

Invalidates the entire surface of the control and causes the control to be redrawn.