How to display a notification form on top of the main form?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a separate thread that handles data transfer operations (with a mobile
device). I've set things up so that a small notification form is displayed
in the lower right corner of the window. This all works fine.

But what I can't figure out how to do is to get it to display on top of my
main form, if the main form is maximized. I've tried all of the following:

statusForm = new frmNotify();
statusForm.Show(); // Display Notification Window asynchronously

statusForm.Focus();
BringWindowToTop((int) statusForm.Handle);
SetForegroundWindow(statusForm.Handle);

With the last two being API calls. But nothing seems to work. I KNOW that
this notification form will display over top of the main form because I can
do so manually but I can't seem to do so programmatically. What am I missing?
 
Hi Robert,
I am not sure why you can't get the form to show ontop of your main form,
unless the main form has a proprety like TopMost set to true.

You could set your small form to have it's TopMost property set to true
and see if that helps you, then it will always be ontop of the other form.

Mark.
 
Mark,

Coming from the VB6 world, I wasn't aware of the TopMost property. I just
checked and both forms had it set to False. So I set my Notification form's
TopMost property to True and voila, it worked.

Thank you!!!

P.S. I think I need more coffee and less sleep (or is it the other way
around?)
 
If you need the notification form to display over all open windows, you
can set the TopMost property of the form to true
statusForm.TopMost=true;

If you just need the notification form to display just over your main
form whenever your main form is in view, then you need to set the Owner
property of your notification form.

statusForm.Owner=mainForm;
// OR
mainForm.AddOwnedForm(statusForm);

However, keep in mind that when a form is owned by another form, it is
minimized and closed with the owner form. For example, if Form2 is
owned by form Form1, if Form1 is closed or minimized, Form2 is also
closed or minimized.

Sarin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top