Question MessageBox always on top

cashdesk

Member
Joined
Jul 5, 2011
Messages
5
Programming Experience
3-5
Hi,

I'm new to Windows apps having done everything so far in ASP.NET.

I have an application that has a timer within the main form. Every 5 minutes it checks the database for notifications and if any are due it displays the details in a messagebox. If the main form is the active form, it works fine (message displayed). Even if I create another form and display that modally, the message is still displayed. If I minimize this second form, the message is displayed.

However, if I am writing an email when the timer is called, the message box isn't displayed on top.

Is there any way to make sure the MessageBox.ShowDialog method always displays the dialog as topmost?

I have tried using a new form instead of MessageBox.Show, setting the TopMost property to true, but that didn't work, either.
 
I would recommend against that. Personally, I find it extremely annoying when I'm entering text into one window and another window takes focus. I would recommend one of two options:

1. A balloon tip on a system tray icon.
2. A toast window.

The first option is built into the Windows Forms NotifyIcon component. The second option is a window that either slides up above the system tray and then slides back down again or else fades in and fades out again. This code was written some time ago, so it could probably be improved upon, but here's a toast example:

Animated Window Effects with "Toast" popup demo
 
I tried your Toast form and while it displays above the taskbar, it only does so if the parent form is the active form. If I open Excel or IE and they are the active window, the toast form does not appear over the top of them.

I also had issues initially. I would open the form in a TimnerCallBack method but then it wouldn't react to user intereaction. I then changed Dim slice AsNew ToastForm(15000, message) to this:

Using _form AsNew ToastForm(15000, message)
Application.Run(_form)
EndUsing

As I said, it displays, but only if the calling form is the active form.

Any ideas?
 
Last edited:
I suggest that you go back and read the last edit on the first post of that thread. I just downloaded that test project and ran it in VS 2010 and it worked as it was supposed to, i.e. the toast forms were displayed in front of other forms.
 
Back
Top