Changing the enable/disable state of a form button from a Class

First off - I'm fairly new to C#.  I have a central form (MainForm), with a panel.  This panel is used to load other forms into it.  Along the bottom of MainForm, there are five buttons - and each one has code (see below) that loads the right form into the panel, changes the text/caption of MainForm, and enables/disables the five buttons depending on which form is selected/loaded (this is the bit I am having trouble with).

        private void JournalButton_Click(object sender, EventArgs e)
        {
            JournalForm var = new JournalForm();
            Nav(var, HomeContentPanel,"Journal");
        }

Open in new window


public void Nav(Form form, Panel panel, string formCaption)
        {
               //Loads form into Panel
            form.TopLevel = false;
            form.Size = panel.Size;
            panel.Controls.Clear();
            panel.Controls.Add(form);
            form.Show();

               //Sets Text/caption of MainForm
               this.Text = formCaption;

               //Enables/disables button
              HomeButton.Enabled = form.Name.ToString() != "HomeForm";
              JournalButton.Enabled = form.Name.ToString() != "JournalForm";
        }

Open in new window


This works perfectly.  However, I wanted to move the Nav method to another class, so that I can set the panel from somewhere other than the five buttons.

Just modifying the code slightly with the MainForm variable at the start - it all works.  Except I cannot enable/disable the five buttons.

public static void NavX(Form frmMain, Form form, Panel panel, string formCaption)
{
       frmMain.Text = formCaption;
       
       frmMain.HomeButton.Enabled = form.Name.ToString() != "HomeForm";
       frmMain.JournalButton.Enabled = form.Name.ToString() != "JournalForm";
}

Open in new window


I get the red squiggles at the start of the HomButton and JournalButton code and can't figure out how to update frmMain.  As said, I am new to c#, so there's probably a better/more correct way of doing this,  But just needed a bit of advice.
Andy BrownDeveloperAsked:
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.

Chris StanyonWebDevCommented:
Hey Andy,

By default, when you add a control, such as a button, to a form, it will have it's access modifier set to Private. This means that you can only access that control from within the form itself. As you need to access the control from outside of the form, you will need to change it's modifier. You can do this easily enough from the form designer. Select you button, and view the properties. You'll see a property caled Modifiers - change that to Internal (or possible Public depending on your setup).

You should then be able to access the buttons from another class.

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
Andy BrownDeveloperAuthor Commented:
Fantastic - thank you so much.
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.