开发者

How to call a method after user control is visible

开发者 https://www.devze.com 2023-01-29 17:34 出处:网络
I have created a Windows application in C# with two user controls. When the form loads first user control is loaded(and shown)and when I click Next I load s开发者_如何学JAVAecond user control.

I have created a Windows application in C# with two user controls.

When the form loads first user control is loaded(and shown)and when I click Next I load s开发者_如何学JAVAecond user control.

Now I want a method from this user control to be called once the user control is visible.

I am not able to do so. If am call the method from Load event it gets fired before the control is visible.

Can someone please guide me on how should I make the call of method after the control is visible.


You probably want to use the VisibleChanged event.

For example:

userControl2.VisibleChanged += new EventHandler(this.UserControl2VisibleChanged);

private void UserControl2VisibleChanged(object sender, EventArgs e)
{
   if(userControl2.Visible)
   {
      CallMyMethodIWantToRunWhenUserControl2IsVisibleHere();
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消