1

I have a problem because I'd like to call newProjectNewFrom over top Form1 that is a main form. If run my program the new windows will be hide under From1. The Form1 is this.WindowState = FormWindowState.Maximized;

private void NewProjectMainMenu_Click(object sender, EventArgs e)
{
   Form2 newProjectNewForm = new Form2();
   newProjectNewForm.ShowDialog();
}

current situation

I'd like to get following situation goal

Pilgerstorfer Franz
  • 8,303
  • 3
  • 41
  • 54
meernet
  • 386
  • 1
  • 4
  • 16
  • 1
    Did you check if **form1** has set [topMost](https://msdn.microsoft.com/en-us/library/system.windows.forms.form.topmost(v=vs.110).aspx) property to true? – Pilgerstorfer Franz Mar 08 '15 at 16:20
  • Duplicate of http://stackoverflow.com/questions/944897/show-a-child-form-in-the-centre-of-parent-form-in-c-sharp – Marius Ungureanu Mar 08 '15 at 16:24
  • 1
    Normally, if you parent the dialog form correctly, it will do what you want (well, you still need to set the `StartPosition` property correctly). That means passing `this` to `ShowDialog()`: i.e. `newProjectNewForm.ShowDialog(this);` Note that you normally should _not_ need to set `TopMost`. – Peter Duniho Mar 08 '15 at 16:25
  • Glad I could help@meernet - perhaps you may consider voting my answer up - and/or selecting it as best answer. – Pilgerstorfer Franz Mar 08 '15 at 16:32
  • @PilgerstorferFranz - perhaps you may consider voting my question ? :) – meernet Mar 08 '15 at 16:41

2 Answers2

0

Have you tried passing Form1 as owner inside ShowDialog? like this? -

private void NewProjectMainMenu_Click(object sender, EventArgs e)
{
   Form2 newProjectNewForm = new Form2();
   newProjectNewForm.ShowDialog(this);
}

as mentioned in msdn here? - https://msdn.microsoft.com/en-us/library/w61zzfwe(v=vs.110).aspx

Note: Give a little bit more time to reading documentations. Don't just ask questions for such an easy answer.

brainless coder
  • 6,310
  • 1
  • 20
  • 36
0

So then - here is it as an answer. I think you've set TopMost property of form1 to true.

As MSDN mentions

A topmost form is a form that overlaps all the other (non-topmost) forms even if it is not the active or foreground form. Topmost forms are always displayed at the highest point in the z-order of the windows on the desktop. You can use this property to create a form that is always displayed in your application, such as a Find and Replace tool window.

Just set it to false, and it should do the trick!

Pilgerstorfer Franz
  • 8,303
  • 3
  • 41
  • 54