switching the visibility of a menuStrip on a different form on and off

Hi,

I have two windows forms in a C# application. One called frmMessages and the second frmAdmin.

On the frmMessage form I have a menu called moveToToolStripMenuItem, which I need to make invisible from frmAdmin.

That was achieved using the code below. However, another problem crept up. Every time  frmMessage is re-loaded the menuStrip is
back to its original position. So, what I really need is to keep the strip invisible until switched to visible and, when switched to visible, stays visible until switched to invisible.

I created the following public method  on frmMessages:

public void ShowHideMenu()
        {
             this.Visible = true;
            ToolStripMenuItem item = new ToolStripMenuItem();
            item = this.moveToToolStripMenuItem;
           
            if (item.Visible == true)
            {
                item.Visible = false;
            }
           
        }

In frmAdmin I created a button that calls the above method:

 private void button1_Click(object sender, EventArgs e)
            {
             
                frmMessage Frm = new frmMessage();
                Frm.ShowHideMenu();

            }

Please advise. Thank you.
adamtraskAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
>>So, what I really need is to keep the strip invisible until switched to visible and, when switched to visible, stays visible until switched to invisible.

Sounds like you want a static bool member variable to control the visibility.  A static variable is common to all instances of the class.
public static bool bFlipMenu = true;
public void ShowHideMenu()
        {
             this.Visible = true;
            this.moveToToolStripMenuItem.Visible = bFlipMenu;
        }

....

private void button1_Click(object sender, EventArgs e)
            {
             
                frmMessage Frm = new frmMessage();
[i]Frm.bFlipMenu = !Frm.bFlipMenu;  //swap between visible and hidden each time this function is called[/i]
                Frm.ShowHideMenu();

            }

Open in new window


You will probably need to adjust the initial setting of bFlipMenu (true/false).  Note also if the only way you display this frmMessage is via this button click then you need to modify the functionality - the method I show changes the setting each time this button click routine is run.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
adamtraskAuthor Commented:
Thank you Andy
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.