Click here to Skip to main content
13,193,468 members (52,134 online)
Rate this:
 
Please Sign up or sign in to vote.
Hi,

I have a user control and i need to edit some things on the event similar to "Shown" with forms.

I tried the following but that does not work:

Added the following line to the designer:

this.Shown += this.HandleControlShown


and added this to the class of the control:

public event EventHandler Shown;
 
private void HandleControlShown(object sender, EventArgs e)
{
    this.OnShown(EventArgs.Empty);
    //code to execute on shown event goes here.... but does not execute
}
 
protected virtual void OnShown(EventArgs e)
{
    EventHandler handler = this.Shown;
    if (handler != null)
    {
        handler(this, e);
    }
}


Where am i doing something wrong?
Posted 6-Nov-12 2:47am
Comments
__John_ 6-Nov-12 8:58am
   
UserControl does not have a Shown event, but it does have a Load event.
pieterjann 6-Nov-12 9:04am
   
I know, but I need the Shown event, the Load event is only casted once. Isn't there a way to add the Shown event manually?
__John_ 6-Nov-12 9:19am
   
You can add your own event but you would need some trigger to fire it.
What do you mean by Shown? i.e. Bring to front? Paint? Or something else?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Eevent declaration code, may be helpful to you.
//declare a delegate
public delegate ShownEventHandler(string args);
 
public event ShownEventHandler Shown;
private void HandleControlShown(object sender, EventArgs e)
{
 if(this.Shown!=null)
 {
    this.Shown(String.Empty/*your args*/);
    //code to execute on shown event goes here.... but does not execute
 }
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.171018.2 | Last Updated 6 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100