By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,771 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,771 IT Pros & Developers. It's quick & easy.

Event that is invoked after a form has loaded

P: n/a

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.
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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?

"Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
news:uY**************@cpmsftngxa06.phx.gbl...

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" <dq*****@netiq.com>
| 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: <#4**************@TK2MSFTNGP10.phx.gbl>
| 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!TK2MSFTN GP10.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.
|
|
|

Nov 15 '05 #2

P: n/a

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" <dq*****@netiq.com>
| References: <#4**************@TK2MSFTNGP10.phx.gbl>
<uY**************@cpmsftngxa06.phx.gbl>
| 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: <Oa**************@TK2MSFTNGP11.phx.gbl>
| 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!TK2MSFTN GP11.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?
|
| "Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
| news:uY**************@cpmsftngxa06.phx.gbl...
| >
| > 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" <dq*****@netiq.com>
| > | 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: <#4**************@TK2MSFTNGP10.phx.gbl>
| > | 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!TK2MSFTN GP10.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.
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.