none
Change MenuStrip Rendermode runtime RRS feed

  • Question

  • Hi,

    I want to change the color of some components on a form. It seems that i can not access the menustrip Rendemode. (I don't want to set i direct in the Property window of the designer).
    how can i access the menustrip rendermode?
    See the "--> this is not allowd ???" This is the part that doesn't work

    What am i missing?

    error message:

    Error CS1061 'Control' does not contain a definition for 'RenderMode' and no accessible extension method 'RenderMode' accepting a first argument of type 'Control' could be found (are you missing a using directive or an assembly reference?)


    using System; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; namespace TopData { public class ApplicationColor { private byte R; //99 private byte G; //108 private byte B; //135

    public ApplicationColor(byte ColorRed, byte ColorGreen, byte ColorBlue)
            {
                this.R = ColorRed;
                this.G = ColorGreen;
                this.B = ColorBlue;
            }

    public void SetFormColor(Form frm) { try { if (frm != null) { frm.BackColor = Color.FromArgb(R, G, B); //Form back color foreach (Control c in frm.Controls) { if (c is MenuStrip) { c.BackColor = Color.FromArgb(R, G, B); c.ForeColor = Color.White;
    c.RenderMode = ToolStripRenderMode.System; --> this is not allowd ??? c.Renderer = new ToolStripProfessionalRenderer(new MenuColorTable());--> this is not allowd ??? } if (c is StatusStrip) { c.BackColor = Color.FromArgb(R, G, B); } if (c is Panel) { c.BackColor = Color.FromArgb(R, G, B); } } } } catch (Exception ex) { //TODO... } } } }




    Friday, October 11, 2019 5:00 PM

Answers

  • Hi,

    I found it. Still do not know why the above does not work...

    This works:

    foreach (Control c in frm.Controls)
                        {
                            if (c is MenuStrip changedMenu)
                            {
                                changedMenu.BackColor = Color.FromArgb(R, G, B);
                                changedMenu.ForeColor = Color.White;
                                changedMenu.RenderMode = ToolStripRenderMode.System;
                                changedMenu.Renderer = new ToolStripProfessionalRenderer(new MenuColorTable());
                            }


    • Marked as answer by HansvB69 Friday, October 11, 2019 8:32 PM
    • Edited by HansvB69 Friday, October 11, 2019 8:45 PM
    Friday, October 11, 2019 8:32 PM

All replies

  • This here explains setting the rendermode

    https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.toolstrip.rendermode?view=netframework-4.8

    Friday, October 11, 2019 5:08 PM
  • this works: (but is not what i need)


    MenuStrip ms = new MenuStrip();
    ms.RenderMode = ToolStripRenderMode.System;

    What is different when i try this:


    foreach (Control c in frm.Controls)
                        {
                            if (c is MenuStrip)
                            {
                                c.RenderMode = ToolStripRenderMode.System; --> Does not work
                                c.Renderer = new ToolStripProfessionalRenderer(new MenuColorTable());
                            }
    
    }
    
    
    



    Friday, October 11, 2019 7:10 PM
  • Hi,

    I found it. Still do not know why the above does not work...

    This works:

    foreach (Control c in frm.Controls)
                        {
                            if (c is MenuStrip changedMenu)
                            {
                                changedMenu.BackColor = Color.FromArgb(R, G, B);
                                changedMenu.ForeColor = Color.White;
                                changedMenu.RenderMode = ToolStripRenderMode.System;
                                changedMenu.Renderer = new ToolStripProfessionalRenderer(new MenuColorTable());
                            }


    • Marked as answer by HansvB69 Friday, October 11, 2019 8:32 PM
    • Edited by HansvB69 Friday, October 11, 2019 8:45 PM
    Friday, October 11, 2019 8:32 PM