Event that is invoked after a form has loaded

  • Thread starter Thread starter David N
  • Start date Start date
D

David N

Hi All,

The OnLoad() event is invoked automatically when a form is being loaded. Do
we have another event that is invoked automatically after a form has
completed loading?

Thanks.
 
Hi Jeffrey,

Thanks for your reply. How do I trap a Windows's message in C# anyway?
Speaking otherwise, how do I trap the WM_SHOWWINDOW and/or WM_ACTIVATE?
 
Hi David,
 
Can you tell me why you want to handle the form right after the form’s load?
Maybe I can help you.

To trap Windows’s message in C#, you should override the Form’s WndProc
method.
 
My sample code was listed below:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace winformmessage
{
public class Form1 : System.Windows.Forms.Form
{
private const int WM_SHOWWINDOW=0x18;
static bool firsttime=true;
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code

private void InitializeComponent()
{
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{

}
protected override void WndProc(ref Message m)
{

switch(m.Msg )
{
case WM_SHOWWINDOW:
if(firsttime)
{
MessageBox.Show ("You application run");
}
break;
default:
break;
}
base.WndProc (ref m);
}
}
}


You may use API Text viewer which is shipped with Visual Studio 6.0 to get
the message’s value or reference the following page if you don’t have that
tool available.

http://doc.ddart.net/msdn/header/include/winuser.h.html

Hope this helps.

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: " David N" <[email protected]>
| References: <#[email protected]>
<[email protected]>
| Subject: Re: Event that is invoked after a form has loaded
| Date: Wed, 30 Jul 2003 09:21:14 -0700
| Lines: 62
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: pat-50.bel.netiq.com 65.219.170.50
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:173009
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi Jeffrey,
|
| Thanks for your reply. How do I trap a Windows's message in C# anyway?
| Speaking otherwise, how do I trap the WM_SHOWWINDOW and/or WM_ACTIVATE?
|
| | >
| > Hi David,
| >
| > I think the form's OnLoad() event is fire when the WM_CREATE message is
| > sent.
| >
| > I use the Spy++ to monitor the messages during the creation of a form.
| > I found that the form's WM_SHOWWINDOW message was sent after the
| WM_CREATE.
| > When this message is sent, the form has already been created, so you can
| > override the form's WndProc method and process WM_SHOWWINDOW message.
| >
| > In addition, I found that the child controls of the form was created
after
| > the WM_SHOWWINDOW message was sent, so you should process form's
| > WM_ACTIVATE message to make sure that the child controls are created.
| >
| > Hope it helps.
| >
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | From: " David N" <[email protected]>
| > | Subject: Event that is invoked after a form has loaded
| > | Date: Tue, 29 Jul 2003 13:56:04 -0700
| > | Lines: 10
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: pat-50.bel.netiq.com 65.219.170.50
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:172788
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > |
| > | Hi All,
| > |
| > | The OnLoad() event is invoked automatically when a form is being
loaded.
| > Do
| > | we have another event that is invoked automatically after a form has
| > | completed loading?
| > |
| > | Thanks.
| > |
| > |
| > |
| >
|
|
|
 
Back
Top