close the form from mdi parent when i click to open any other form
i have an administrator form and in this form lot of menu items and all open a new form. but when I open a new from again i will open a new from then new form will b开发者_如何学编程e open but old form will not be closed.there are many form open in administrator form. i wand when i open any form on click a menu item the other form close.
Simply you have to know each form object then you can close it, for example when you want to open one windows you write
new MyForm().ShowDialog();
Ok instead you can declare a form object in the top of your administrator form:
Form oldForm;
when user press one of your forms list:
if (oldForm != null)
oldForm.Close();
Form newOne = new UsersForm();
oldForm = newOne;
newOne.ShowDialog();
精彩评论