0
Answer

ToolStripItemSeparator color?

Theis Andersen

Theis Andersen

14y
2.5k
1
Hi!
I am trying to change the entire colorschema in my menu. And the only thing that is not changing is the toolstripseparator. I have a popupmenu where the same algorithms are used and the Effects on the popup is showed! So my question becomes: Those anyone know a solution to this??

I recursivevly loop through all the menus to set back and forecolor.

 private void loopmenuitems(ToolStripMenuItem item ,Color c, Color text)

        {

            item.BackColor = c;

            item.ForeColor = text;

            if (item.HasDropDownItems)

            {

                foreach (Object child in item.DropDownItems)

                {

                    try

                    {

                        ToolStripMenuItem menuitem = (ToolStripMenuItem)child;

                        loopmenuitems(menuitem, c, text);

                    }

                    catch

                    {

                        ToolStripSeparator sep = (ToolStripSeparator)child;

                        sep.ForeColor = text;

                        sep.BackColor = c;

                    }

                }

            }

        }


        private void looopMenu(Color c, Color text)

        {


            //Doesn't WORK
            menuStrip1.BackColor = c;

            menuStrip1.ForeColor = text;

            foreach (Object m in menuStrip1.Items)

            {

                try

                {

                    ToolStripMenuItem items = (ToolStripMenuItem)m;

                    loopmenuitems(items, c, text);

                }

                catch

                {

                    ToolStripSeparator sep = (ToolStripSeparator)m;

                    sep.ForeColor = text;

                    sep.BackColor = c;

                }

            }

            // WORKS
            popupmenu.BackColor = c;

            popupmenu.ForeColor = text;

            foreach (Object menuitem in popupmenu.Items)
            {

                try

                {

                    ToolStripMenuItem items = (ToolStripMenuItem)menuitem;

                    loopmenuitems(items, c, text);

                }

                catch

                {

                    ToolStripSeparator sep = (ToolStripSeparator)menuitem;

                    sep.ForeColor = text;

                    sep.BackColor = c;

                }

            }

        }