I have two forms in my application MainForm and HexCompare . If I move from my application to another window, I click on one of two forms, and only one of them comes to the fore. How can I do this, if I click on one of the two forms, this will lead to the beginning of all open forms in the application? Right now I need to select each form separately to move them to the top of my window stack (and this can be very annoying because HexCompare has ShowInTaskbar set to false
A good example of this work, as I want, is how most search dialogs work. If you click the search dialog, it brings the main form to the foreground if it is hidden by another application, and if the main form is clicked, the search dialog will appear in front if it is hidden by another application.
How MainForm is MainForm .
[STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); }
How is HexCompare called
private void lstCaputres_SelectedIndexChanged(object sender, EventArgs e) { var selectedItem = (Tuple<DateTime, byte[]>)lstCaputres.SelectedItem; if (hexCompare == null || hexCompare.IsDisposed) { hexCompare = new HexCompare(selectedItem.Item2); hexCompare.Show(); } else hexCompare.ChangeValue(selectedItem.Item2); }
EDIT:
It seems that the value of HexCompare Parent is Null . If I could somehow install it on MainForm , would that solve my problem, and if so, how did I install it?
EDIT2:
I decided to solve it using the Tigran solution, but it causes flickering, since each form is brought to the forefront if there is a better solution that interests me.
//In MainForm.cs private void MainForm_Activated(object sender, EventArgs e) { hexCompare.BringToFront(); this.BringToFront(); } //in HexCompare.cs private void HexCompare_Activated(object sender, EventArgs e) { parent.BringToFront(); this.BringToFront(); }