Accessing a form being created

  • Thread starter Thread starter paulo
  • Start date Start date
P

paulo

Hello,

I would like to know if it possible to receive an event or intercept a
message so I can access every form I create in my application. I want to
add some functionality to my forms, but I want to do it in runtime. Is
it possible to be notified every time a new form is created and before
it is shown, so I can access it, for example, to add one specific
control to it or to subscribe an event?
Thanks in advance for any help given.

Regards,
paulo
 
How about overriding WndProc and creating a custom message (WM_USER+1)
and from each form's Load event handler do a SendMessage call of the
custom message? You could even send an integer value that could tell
you which form is sending the message. Then catch the message in
WndProc's switch statement.
-Mike
 
Hello Paulo,

Every form has a form_load method, we may add code here, for example,

private void Form1_Load(object sender, EventArgs e)
{

DoSomething(this);

}


DoSomething() is a glabal ro external function, and accept current form as
parameter. Can this help your question?

Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Hello Luke and thank you for your reply,

I probably didn't make myself clear. What I really need is to do that in
runtime. I don't want to go to every form in my application and put that
event into it. I also don't want to inherit a new class from Form which
implements what I want.
I want to catch every form that is created in my application in runtime
and assign one or two events to it, or do any other thing with it.
Is there any way to do this on the application level.
I've tried some approaches, including message filtering with
IFilterMessage, without success.
Do you know of any way to do this?

Regards,
paulo
 
As I know, there is no such event/message in application level, so I think
inheriting a customized Form class in the application should be proper
solution for this issue.

Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top