Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an mdi form with three child say form1 form2 an form3 the childs are accessd through a menustrip from the parent form.i want that whenever u open form1 by the click of its toolstripmenuItem and click a button in it, i want that another button in another form say form2 should b enabled witout showing the form2 unless u click on the form2menustripitem before u will see the change, that is ,i want the change to occure directly on the form and not a new instance of the form2.please i need help on this codes will b very helpful Thank in advance
Posted
Comments
Oshtri Deka 5-Sep-12 2:38am    
Can you rewrite your question and use proper punctuation?
You know, as if you want people to understand your problem.
Ese ochuko 5-Sep-12 9:01am    
Wat am trying to say is that, i av an mdiparent form wit two child form1 which has a button an form2 which also has a button but its disabled,both of the forms are accessed from a menustrip in the mdiparent. Now i want that when a user clicks on the button in form1, the button in form2 should be enabled.

Hi,


I guess you want to change the settings of form 2 based on the selection in form1.
If so, you can save the selection of the form1 and make the settings for form2 on load of form2.

Hope this helps.
 
Share this answer
 
Comments
Ese ochuko 5-Sep-12 12:23pm    
Please can u give me a complete example with codes thnx
Hi Ese Ochuko,

U can resolve this problem in 2 ways,

one approach is to use panels instead of forms..so that all the controls(controls of all panels) can be with in the single form..still we can use as diff forms .
i think code not required for this..

2nd approach is ,to have the effect of settings done on form2 from form1..you should use the same instance for opening that form.(usually form is opened by creating object for it).

i.e ,


C#
form1()
{

 Form2 frm2 =new Form2();

 //controlling Form2 button from From1 menu strip
  void menuStripItem1_click(object sender,EventArgs e)
  {

   if(e.clicked==true)
    frm2.button1.enabled = true;

  }

 //suppose form 2 is opened by clicking menustrip item 2(u call in the same way where you want)
 void menuStripItem2_click(object sender,EventArgs e)
  {
   frm2.show();
  }

}
 
Share this answer
 
Comments
Ese ochuko 6-Sep-12 4:08am    
Thank u very very much for your reply the thing is am a biginer learning by practicing.the thing is that fom1 is not the form with the menu strip, the menustrip is present on the parent form.take for instance the form1 is a login form and i want that when the user logs in with a particular role, some buttons on different child forms are enabled and some will be disabled as wel,so that the user is retricted to specific information that concerns his role.thanks again pls code example wil b of great help. thanks once again for ur help
JANARDHAN GURRAM 6-Sep-12 13:41pm    
form1 is not having the menu strip i am confused which one is parent form can you suggest me the flow,is it

loginform --> parent form(with menu strip??)-->form2 or form3 ??
Ese ochuko 6-Sep-12 17:50pm    
Yes thats the flow login>mdiparent>form2 an form3.
The mdiparent has the menustrip. The login form is accesd from a toolstripbutton in the mdiparent.i want that wen you login with a specific role ,some buttons in form2 and form3 are enabled. So that when i click on either form2 or form3 menustrip item in the mdiparent, i should b able to work with the enabled buttons .tnx.if dnt undstand pls ask me again to explain the question more tanks for your time
i have created a sample application which may suit your requirement..u may have to do minor changes

create 4 diff forms

login form with combobox
parent form with menustrip other 3 forms as menu strip items
form2 and 3 with two buttons and two labels each(change all the 4 controls to public)....in which one button is enabled based on user type (1 or 2)from login form.

C#
 public partial class ParentForm : Form
    {
        public LoginForm lgf;
        public Form2 frm2 = new Form2();
        public Form3 frm3 = new Form3();

        public ParentForm()
        {
            InitializeComponent();
        }

        private void form2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frm2.Show();
        }

        private void form3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frm3.Show();
        }

        private void loginFormToolStripMenuItem_Click(object sender, EventArgs e)
        {
            lgf= new LoginForm(this);
            lgf.Show();
        }

    }


//Login Form
public partial class LoginForm : Form
    {
        ParentForm prf;
        public LoginForm(ParentForm prf)
        {
            this.prf = prf;
            InitializeComponent();
        }
       
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem.ToString() == "user1")
            {
                prf.frm2.button1.Enabled = false;
            }
            else
                prf.frm3.button4.Enabled = false;
        }
    }


//Form2 with 2 buttons and 2 labels
   public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
    }

//Form3 with 2 buttons and 2 labels
 public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }
    }
 
Share this answer
 
Comments
Ese ochuko 9-Sep-12 3:23am    
Hi gurram

thanks for everytin you are so kind.the code you gave to me is working as i expected, but there is a little problem. The problem is when i run the code and open form2 or form3 it worked as i expected it.but when i close it and try to re- open it by cliking on the menustrip it dsiplays an exception "cannot access a disposed object. Object name form2" i tried to handle this my self but cud not can u please hhelp me on this.thanks for everytin
Hi Ese ochuko,

that problem is caused because of calling the same object after its disposal. it can be solved by extending the form closing event..

select the properties (in form designer view) for form2 and form3 go to the events
and double_click on the form closing event in the code generated copy this (for both in between parenthesis)..

C#
e.Cancel = true;
this.Visible = false;
 
Share this answer
 
v2
Comments
Ese ochuko 10-Sep-12 4:01am    
Thank you very much, you are a genus
JANARDHAN GURRAM 10-Sep-12 4:42am    
ha ha :-)

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