When using the Focus()
method, the targeted form acquire focus but is also brought in front of the other forms.
Is there a way to avoid this z-order modification ?
Here is a short example :
class MyForm : Form
{
static void Main(string[] args)
{
MyForm f1 = new MyForm()
{
Text = "f1"
};
f1.Show();
MyForm f2 = new MyForm()
{
Text = "f2"
};
f2.Show();
Button b1 = new Button();
b1.Click += (sender, e) => f2.Focus();
f1.Controls.Add(b1);
Button b2 = new Button();
b2.Click += (sender, e) => f1.Focus();
f2.Controls.Add(b2);
Application.Run(f1);
}
}
When clicking the button in f1
, f2
will gain focus but will also come in front of f1
(which is the thing I'd like to avoid).