Any event?

  • Thread starter Thread starter Jacek Jurkowski
  • Start date Start date
J

Jacek Jurkowski

Is there an event that fires globally for application
whenever some window is showing? I want to know
about any window displaying in my application ...
 
Hi Jacek,

Thank you for posting in the community!

Based on my understanding, you want to be notified when any window in your
application is showing.

=============================
I think the problem depends on who will be notified when the window is
showing. (Can you tell me this?)

I think in the main form, you may want to show some forms. Then you want
your main form to be notified when these forms are showing.

Normally, you should passing the main form's reference to child form
class(You may add this parameter in child form's constructor). Then in the
child form's Load event, you can manipulate the Main Form(This is some kind
of notification).

Like this:

//Create a customized child form's constructor
Form mainform;
public Form2(Form f)
{
this.mainform=f;
}

// In the Main Form, show up the child form
Form2 f;
private void button_Click(object sender, System.EventArgs e)
{
f=new Form2(this);
f.Show();
}

When the Form2(child form) is showing, it will change the Caption text of
MainForm

=============================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
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.
 
Hi Jacek,

Thank you for posting in the community!

Based on my understanding, you want to be notified when any window in your
application is showing.

=============================
I think the problem depends on who will be notified when the window is
showing. (Can you tell me this?)

I think in the main form, you may want to show some forms. Then you want
your main form to be notified when these forms are showing.

Normally, you should passing the main form's reference to child form
class(You may add this parameter in child form's constructor). Then in the
child form's Load event, you can manipulate the Main Form(This is some kind
of notification).

Like this:

//Create a customized child form's constructor
Form mainform;
public Form2(Form f)
{
this.mainform=f;
}

// In the Main Form, show up the child form
Form2 f;
private void button_Click(object sender, System.EventArgs e)
{
f=new Form2(this);
f.Show();
}

When the Form2(child form) is showing, it will change the Caption text of
MainForm

=============================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
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.
 
Hi!

Im showing some welcome window before Main window
is displayed ... I some circumstances while welcome window
is displayed some other functions shows own forms to the
user. I would like to hide welcome window while some
other is displayed....
 
Hi Jacek,
Im showing some welcome window before Main window
is displayed ... I some circumstances while welcome window
is displayed some other functions shows own forms to the
user. I would like to hide welcome window while some
other is displayed....

If your *welcome* window is displayed in static Main()
method then you can initialize static variable:

private static Form welcomeForm = null;

next you have to handle this form *Closed* event as a static
method e.g.:
private static void welcomeForm_Closed(object sender, EventArgs e) {
welcomeForm=null;
}

and public static method:

public static void CloseWelcomeWindowIfExists() {
if( welcomeForm!=null ) {
welcomeForm.Close();
}
}

Now you can call *CloseWelcomeWindowIfExists* in every form
at *Load* event.

It isn't *best* solution but it should work in any case.
If you will give more precise sample then i revise my code.

Regards

Marcin
 
You sollution has a one weak point ... Everyone must remeber
to chceck for visible welcome window on load but after some time nobody
probably will ... beside that some windows are showing as an reaction
for a event that programmer could not expect to raise while welcome
is still visible ... I prefer most "wrirte and forget" code ...
 
Hi Jacek,

Thanks very much for your feedback.

After viewing your feedback, I am not fully understand your problem. Can
you explain your point more clearly?
As I think, the Marcin's solution should work for you.

Anyway, I will wait for your feedback. Thanks

Best regards,
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.
 
Hi Jacek,

Is your problem resolved?

If you still have any concern, please feel free to feedback, I will help
you.

Best regards,
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.
 
Back
Top