As in: when one form is activated, they are all activated, when one form is minimized they are all minimised and so forth.
I would use a generic list of forms (static member of a class) (List<Form>
) and would set the properties always to the same. e.g. on a minimize event and so on...
Only one window can ever be activated. You are otherwise asking about 'owned' windows. Use the Show(owner) overload. It ensures that when the user activates the main (owner) window, all other forms move to the foreground as well. And get minimized when the main window is minimized.
I suggest the following solution, I hope it is useful:
First: define an interface for the brother forms:
public interface IFormBrothers
{
List<IFormBrothers> Brothers { get; set; }
}
Then implement the interface for all the forms which you want them to be brothers like the following:
public partial class FormB : Form, IFormBrothers
{
public List<IFormBrothers> Brothers { get; set; }
}
public partial class FormA : Form, IFormBrothers
{
public List<IFormBrothers> Brothers { get; set; }
}
Then add the following extension:
public static class BrothersExntension
{
public static void SetAsBrother(this IFormBrothers form, IFormBrothers brother)
{
if (form.Brothers == null)
form.Brothers = new List<IFormBrothers>();
if (form.Brothers.Contains(brother))
return;
form.Brothers.Add(brother);
brother.SetAsBrother(form);
(form as Form).SizeChanged += (s, e) =>
{
foreach (var item in form.Brothers)
(item as Form).Width = (s as Form).Width;
};
}
}
Note: The SizeChanged is just an example, you can repeat that for all the shared behaviors if you could
Finally: Don't forget to add the form to his brothers once:
var f1 = new FormA();
var f2 = new FormB();
f1.SetAsBrother(f2);
f1.Show();
f2.Show();
Note: it's enough to add f1 to f2, because f2 will add f1 internally.
Good luck.