Showing a ChildForm on top, even when ParentForm is hidden

48 views Asked by At

I have an application that’s running silently in the System Tray. Occasionally, I need it to pop-up a small notification form to the end-user.

I’ve attempted to accomplish this w/ a WinForms application that has the bulk of its logic built into a hidden form that’s not displayed to the user. Then, when certain criteria is met, I display a secondary form to the user.

My problem is, this secondary form isn’t always on top, even when I set TopMost = true.

I believe this is because the main form isn’t being displayed, so its child forms can’t take advantage of TopMost = true. I've tried moving TopMost around to a few different places. Any other ideas?

MainForm logic:

ChildForm childForm = new ChildForm(this);

int x = (Screen.PrimaryScreen.Bounds.Width / 2) - (childForm.Width / 2);
childForm.StartPosition = FormStartPosition.Manual;
childForm.Location = new Point(x, 0);
childForm.ShowDialog();
//childForm.TopMost = true;

ChildForm logic:

public ChildForm(MainForm mainForm)
{
    InitializeComponent();
    //this.TopMost = true;
}
1

There are 1 answers

0
WEFX On BEST ANSWER

After stepping into some breakpoints, I realized that the childForm will be TopMost as long as I set that property after the childForm has been initialized properly and shown. I was able to force this to work by setting the TopMost command within the Shown event like this:

private void ChildForm_Shown(object sender, System.EventArgs e)
{
    this.TopMost = true;
}