Click here to Skip to main content
12,949,700 members (70,826 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
OriginalGriff 5,489
CHill60 3,380
Maciej Los 2,913
Jochen Arndt 1,935
ppolymorphe 1,820


Advertise | Privacy | Mobile
Web02 | 2.8.170524.1 | 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