alex4
alex4

Reputation: 227

How do I know when an user call hide or show method on custom user control?

I have a custom user control. Is there any way to know when an user call hide or show methods ?

winforms, 2.0

Upvotes: 1

Views: 340

Answers (1)

Shekhar_Pro
Shekhar_Pro

Reputation: 18430

Theres a Visible Changed Event which is raised when control is shown or hidden or simply when its visibility is changed.

Remember that Hiding the control is equivalent to setting the Visible property to false. After the Hide method is called, the Visible property returns a value of false until the Show method is called.

Here is a sample code:

private void Button_Click(object sender, EventArgs e)
{
   myLabel.Visible = false;
}

///Somewhere in your form load or wherever you like
private void form1_Load(object sender, EventArgs e)
{
   myLabel.VisibleChanged += new EventHandler(this.Label_VisibleChanged);
}

private void Label_VisibleChanged(object sender, EventArgs e)
{
   MessageBox.Show("Visible change event raised!!!");
}

Similarly you can do for any control, even User Control

Upvotes: 2

Related Questions