Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I Have a main form that has a menustrip with toolstrips that say login, admin and user. and I have disabled the toolstrips that say admin and user. because when i log in and the username for the loginform does not say admin only the user toolstrip should be enabled. but the problem I am having is that the code behind the login button does not seem to enable either of the toolstrips.
the login toolstrip pops up a form with the fields namely Username and password and a loginBtn

C#
if (userID.Equals(txtUserID_.Text) || password.Equals(txtPassword_.Text))
                    {
                        user = txtUserID_.Text;
                        MessageBox.Show("User Identity and Password Verified");
                        //
                        if (txtUserID_.Text != "Admin")
                        {
                            mnFrm.adminTS.Enabled = true;
                        }

And the code in the toolstrips are
C#
        private void adminToolStripMenuItem_Click(object sender, EventArgs e)
      {
          adminTSMenuItem.Enabled = false;
      }
private void faultToolStripMenuItem_Click(object sender, EventArgs e)
      {
          faultTSMenuItem.Enabled = false;
      }
Posted
Updated 25-Jun-13 1:57am
v3
Comments
JoelonJada 25-Jun-13 6:53am    
Thanks In advance Guys
Sunasara Imdadhusen 25-Jun-13 7:10am    
are you using MDI parent or child form?
JoelonJada 25-Jun-13 8:02am    
Child Form .MDI parent is main and the login form is a child form

Refer this article it will help you.
Study it and change for you code.
http://www.c-sharpcorner.com/uploadfile/mma1979/how-to-access-mdiparent-controls-from-child-forms/[^]
 
Share this answer
 
Comments
JoelonJada 25-Jun-13 8:00am    
Thank you but in looking at your code i realised that the form2 had no controls on it. say it had a button and that the button would enable the other toolstrips called view and tools assuming the two toolstrips are disabled on runtime. wht code would be behind the button
Pallavi Waikar 25-Jun-13 8:47am    
As per your question you want to access mdi control toolstrip from your child form and that article is all about that i.e How to Access MdiParent Controls From Child Forms..understand it and implement it in your code.
JoelonJada 25-Jun-13 9:54am    
Okay thank you.
okay so i solved it myself by creating a public method for the disable controls in the parent form and then calling in it in the child form.
//this in the parent form
C#
//disables fault/complains and admin
       public void DisableControls()
       {
           adminTSMenuItem.Enabled = false;
           //faultTSMenuItem.Enabled = false;
       }

       //enables fault/complains and admin
       public void EnableControls()
       {
           adminTSMenuItem.Enabled = true;
           faultTSMenuItem.Enabled = true;
       }


//login child form
C#
f (txtUserID_.Text != "Admin")
                        {
                            MessageBox.Show("User Identity and Password Verified");
                            ((Main)this.MdiParent).DisableControls();
                        }
                        else
                        {
                            ((Main)this.MdiParent).EnableControls();
                        }
                        this.Close();


Thanks Guys help me alot.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900