473,563 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Event that is invoked after a form has loaded


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
2 22643
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.mi crosoft.com> wrote in message
news:uY******** ******@cpmsftng xa06.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.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: pat-50.bel.netiq.co m 65.219.170.50
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1727 88 | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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

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.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;

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

public Form1()
{
InitializeCompo nent();
}

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

#region Windows Form Designer generated code

private void InitializeCompo nent()
{
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHan dler(this.Form1 _Load);

}
#endregion

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

private void Form1_Load(obje ct sender, System.EventArg s 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.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: pat-50.bel.netiq.co m 65.219.170.50
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP11.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1730 09
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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.mi crosoft.com> wrote in message
| news:uY******** ******@cpmsftng xa06.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.publi c.dotnet.langua ges.csharp
| > | NNTP-Posting-Host: pat-50.bel.netiq.co m 65.219.170.50
| > | Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
| > | Xref: cpmsftngxa06.ph x.gbl
| microsoft.publi c.dotnet.langua ges.csharp:1727 88
| > | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
17819
by: Sharon | last post by:
I'm writing a new control derived from UserControl. I need to get an event when the control is done resizing. I tried the Resize, SizeChanged, Move and the Layout events and I also tried to override them. But they all invoked when the control is in the middle of the resizing process. I'm not using breakpoints, I'm using trace to see which...
7
3250
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically load one of several controls: private void btnCategory_Click(object sender, System.EventArgs e) { Control myControl =...
8
4303
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender,...
4
1937
by: Antonio Carpentieri | last post by:
Hi all, in my previous post I've wrong typed some tems.. this is the corrected post. in a aspx page I have a repeater like this: <asp:repeater id=repeaterResults runat="server" OnItemCommand="RepeaterResult_Event"> <HeaderTemplate> <table width="515" border="0" cellpadding="3" cellspacing="0"> </HeaderTemplate> <FooterTemplate>
4
4145
by: EvelynAnd Ethan | last post by:
Hi, ItemCommand event not firing from a dynamic user control ,WHERE A DATAGRID HAS BUTTON,when i click on the linkbutton first time the itemcommand event doesnt fire,second time event fires up any answers?? Regards,
4
9059
by: C M Shaw | last post by:
I have a form which I want to show modally; it's a fairly old form that's been ported up several versions of VB, and I'd like to keep its rewriting to a minimum. Basically, it is used in this sequence: 1. The form is shown. The Form_Load event does some initialization. 2. Further parameters are passed to this form. 3. We actually need...
1
1531
by: John F | last post by:
Hello, I'm dynamically loading a child form saved in a DLL. I have this code working and it's pretty straightforward. What I'd like to do is pass an object type to an invoked method in the child form as soon as it's loaded. It seems I can get the invoke working just fine, but I can't get the object successfully cast inside the invoked...
1
7030
by: superjacent | last post by:
Hope someone can point me in the right direction. When opening a form the 'click' event of the ListBox is invoked (run). I thought the 'click' event of the ListBox is only invoked when clicking it. I've looked all over the preceeding and other events on the form and definitely do not invoke the ListBox 'Click' event. What does happen...
19
3210
by: zacks | last post by:
I have a .NET 2.0 MDI application where the child form has a Tab Control. Each of the Tab in the Tab Control has a Validating event to handle what it should do when the user changes tabs. But these Validating Events are also fired when either the child form or the main (parent) form Close icon is clicked. And I need for these events to know...
0
8101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7631
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7943
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6238
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5479
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3631
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
912
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.