OnLoad works but OnShown doesn't

Hi

I try this ...

#region EVENT HANDLERS

        protected override void OnLoad(EventArgs e)
        {
            MessageBox.Show("this is a test1");
        }

        protected void OnShown(EventArgs e)
        {
            MessageBox.Show("this is a test2");
        }

And the OnLoad Event gets called but the OnShown doesn't.

When I go to the properties and click events It has Load but not Shown.

Any ideas?
thanks
Paul
paulwhelanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

paulwhelanAuthor Commented:
Also when I try to do

protected override void OnLoad(EventArgs e)
        {
            MessageBox.Show("this is a test1");
        }

        protected override void OnShown(EventArgs e)
        {
            MessageBox.Show("this is a test2");
        }

It says

Error      22      'DefaultControlsPlugin.Design.ControlPropertyPages.ElementLabelControlPropertyPage.OnShown(System.EventArgs)': no suitable method found to override      


And in this code theres aLoad but no Show

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Runtime.InteropServices;

namespace System.Windows.Forms
{
    // Summary:
    //     Provides an empty control that can be used to create other controls.
    [Designer("System.Windows.Forms.Design.ControlDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
    [ComVisible(true)]
    [ClassInterface(1)]
    [Designer("System.Windows.Forms.Design.UserControlDocumentDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(IRootDesigner))]
    [DefaultEvent("Load")]
    [DesignerCategory("UserControl")]
    public class UserControl : ContainerControl
    {
        // Summary:
        //     Initializes a new instance of the System.Windows.Forms.UserControl class.
        public UserControl();


.....

//
        // Summary:
        //     Raises the System.Windows.Forms.UserControl.Load event.
        //
        // Parameters:
        //   e:
        //     An System.EventArgs that contains the event data.
        [EditorBrowsable(2)]
        protected virtual void OnLoad(EventArgs e);
        [EditorBrowsable(2)]
0
dstanley9Commented:
OnShown is a method for .NET 2.0 windows Forms classes (not UserControls).
0
paulwhelanAuthor Commented:
Hi dstanley9

Thanks for that.

Can you explain a little more?
What do you mean that its a method for .NET 2.0 windows forms classes?

Can I now use it like OnLoad?

What method should be used to show the message box when the page is shown?

Thanks
Paul
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

dstanley9Commented:
Add the event handler to the form, not the user control (I'm assuming that's where it is based on the code that you posted and the error you received.

Also, it''s better to ADD event handlers rather than OVERRIDE them.  That way you don't kill any existing event handlers.

Here's a few tutorials on event handlers in general:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkEventsTutorial.asp
http://www.c-sharpcorner.com/Code/2002/Mar/EventHandlingInNetUsingCSDD001.asp

e.g.
    // in form or control constructor...
    this.OnLoad += new EventHandler(this_Load);
    // Assign the Shown event handler to the Shown event of the FORM
    this.ParentForm.Shown += new EventHandler(form_Shown);


#region EVENT HANDLERS

        private void this_Load(object sender, EventArgs e)
        {
            MessageBox.Show("this is a test1");
        }

        protected void form_Shown(object sender, EventArgs e)
        {
            MessageBox.Show("this is a test2");
        }
0
paulwhelanAuthor Commented:
Thanks.

I get an error when I try to do

this.OnLoad += new System.EventHandler(this.this_Load);

Error      24      Cannot assign to 'OnLoad' because it is a 'method group'      

Paul
0
dstanley9Commented:
Sorry, that should be

this.Load += new System.EventHandler(this.this_Load);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.