Problem with MdiParent-MdiChildren forms
-
Hi all I’m having 2 problems in C# now. 1. I have a MDIParent form which loads the login form in the form_load event. From there I if the user login successfully, I want to enable all menu items on the menu bar. If the login is fail, I want to disable some menu items there too. This means I want to enable/disable a MdiParent’s element from a child form, please help me how to do that. 2. From question 1, when I want to open a form from the menu, I create an object then just show it like this. frmCustomer frmCus=new frmCustomer(); frmCus.MdiParent=this; frmCus.Show(); But the problem is while a Customer form is opening, when the Customer menu is clicked, it creates another Customer form for me. Is there any way to check weather the form is shown or not before showing it?
-
Hi all I’m having 2 problems in C# now. 1. I have a MDIParent form which loads the login form in the form_load event. From there I if the user login successfully, I want to enable all menu items on the menu bar. If the login is fail, I want to disable some menu items there too. This means I want to enable/disable a MdiParent’s element from a child form, please help me how to do that. 2. From question 1, when I want to open a form from the menu, I create an object then just show it like this. frmCustomer frmCus=new frmCustomer(); frmCus.MdiParent=this; frmCus.Show(); But the problem is while a Customer form is opening, when the Customer menu is clicked, it creates another Customer form for me. Is there any way to check weather the form is shown or not before showing it?
You need to pass the current instance of your parent form to the LoginForm. This way:
LoginForm frmLogin = new LoginForm(this);
While the constructor for LoginForm will be:
public LoginForm(MDIparent frmParent)
{
this.Parent=frmParent;
}This way you will be able to access all the controls of the parent form. For your second problem,
Application.OpenForms
collection is there to help you. If the CustomerForm is already in the collection, just set Focus to it, otherwise create a new instance of it and show.जय हिंद Rajdeep.Net[^] is NOT from India. Proof.[^]
-
You need to pass the current instance of your parent form to the LoginForm. This way:
LoginForm frmLogin = new LoginForm(this);
While the constructor for LoginForm will be:
public LoginForm(MDIparent frmParent)
{
this.Parent=frmParent;
}This way you will be able to access all the controls of the parent form. For your second problem,
Application.OpenForms
collection is there to help you. If the CustomerForm is already in the collection, just set Focus to it, otherwise create a new instance of it and show.जय हिंद Rajdeep.Net[^] is NOT from India. Proof.[^]
-
Thank you for your quick reply. It's very helpful for me, but can you give me more where to put
Application.OpenForms
in? -
Inside the CustomerMenu click event.
ClickEvent:
if CustomerForm is open:
just set the focus on it
else:
Create it
End
जय हिंद Rajdeep.Net[^] is NOT from India. Proof.[^]