If both are defined as TopMost
, will always be on top the last one that was focused or the last one that was opened. But if you want to open the window2, the window1 appears on top, you can call the method .BringToFront();
of window 1.
Example:
Form2 janela1;
private void button2_Click(object sender, EventArgs e)
{
janela1 = new Form2();
janela1.Text = "1";
janela1.StartPosition = FormStartPosition.CenterScreen;
janela1.TopMost = true;
janela1.Show();
}
private void button3_Click(object sender, EventArgs e)
{
Form2 janela2 = new Form2();
janela2.Text = "2";
janela2.StartPosition = FormStartPosition.CenterScreen;
janela2.TopMost = true;
janela2.Show();
if (janela1 != null && !janela1.IsDisposed)
janela1.BringToFront();
}