Search code examples
c#winformsmenustrip

C#, menustrip specific menu open when user have logged in


in my menuStrip i have multiple forms,

So in 1 of them i want to be access only when use is pass from a login form i have create..

Lets say menustrip, menu is on form1, and the login form is Form2,

So how i am gonna comebine this to so menustrip form open when the user first pass the form2 login..

i am searching all day over the net i found only by passing a variable and then if its true the form1 is gonna pop-out but it didnt work well!


Solution

  • Well thinking I got it right "You want to have input in form 1 from form2or something like modify something in form1 from form2"

    It may not be the best but works

    Well the simplest solution that has helped me till now is that you

    1. Make menuStrip modifier from properties to public
    2. create an instance on Form1 in Form2
    3. Modify menuStrip from Form2

    for example we can have

    Form2.cs

     public partial class ViewCars : Form
        {
            Form1 mainForm;
            public ViewCars (Form1 MainForm)
            {
               this.mainForm = MainForm;
            }
        }
    
         private void LoginButton_Click(object sender, EventArgs e)
         {
             mainForm.menuStrip.Visible = false;
         }
    

    Now to when you make the instance of Form2 you need to have give parameter this i.e

    ViewCars view = new ViewCars(this);
    view.Show();
    

    This is not Limited to controls you can do anything with it Good Luck