Calling a sub that's a menu item in C#

bondy666
bondy666 used Ask the Experts™
on
Firstly apologies, this is probably very easy but I'm coming from a VB background and teaching myself C# by throwing myself straight into a project!
I have a form that has a toolstrip menu item which changes the skin of the form. This works fine.
What I would like to do though is for the form to start up, read a regkey which defines the skin it should load and call the same sub which the menustrip item calls. The problem I am having is calling the menu item code.
What I need to do is call the forestWaterToolStripMenuItem sub from the switch statement in the attached code.

Thank you
private void frmDriverMatch_Load(object sender, EventArgs e)
        {

            RegistryKey regKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\DriverMatch");
            if (regKey == null)
            {
                return;
            }
            else
            {
                lblSearchPath.Text = regKey.GetValue("SearchPath").ToString();
                lblSourcePath.Text = regKey.GetValue("SourcePath").ToString();
                string skin = regKey.GetValue("Skin").ToString();

                switch (skin)
                {
                    case "forestWater":
                        {
                            forestWaterToolStripMenuItem_Click;
                        }

                        break;


                }
            }
            
        }

.....


        private void forestWaterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            menuStrip1.BackgroundImage = Properties.Resources.forestwater;
            this.BackgroundImage = Properties.Resources.forestwater;
            dataGridView1.BackgroundColor = Color.DarkGreen;
            dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.OliveDrab;
            RegWrite("Skin", "forestWater");
        }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Make a sub SetBackground and put the code from forestWaterToolstripMenuItem_click in it and from your switch code and from the click event code call the new sub.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial