Skip to content

Theme definitions at runtime. #755

Closed

Description

@itg-assistant

Andi Gordon asked 2017-04-06 13:30:00 UTC

Hi

So I have a theme and have defined some new Colours and Fonts.
The InitializeComponent code seems to reference these like this:

this.label1.BackColor = System.Drawing.Color.FromName("@CMSToolBarButtonBackgroundHover");

And that works, it displays in the desired colour.
But when I put the same code in my application, for example in a MouseHover event handler, it returns "{Name=@CMSToolBarButtonBackgroundHover, ARGB=(0, 0, 0, 0)}" which seems right compared to other places, but it has no effect in the UI.

this.MouseHover += (s, ex) =>
{
this.BackColor = System.Drawing.Color.FromName("@CMSToolBarButtonBackgroundHover");
};

I can change the colour name in InitializeComponent and it changes the initial colour in the UI, I can also change the colour in the event handler to a non-theme colour (eg.FromARGB or Color.Black) but nothing I do in the event handler with the theme defined colour seems to have any effect.

In some cases I can setup buttons and use the theme designer to provide hover effects, but there are instances I need to do this programatically.

Any idea why this doesn't work ?

Thanks,

Andi Gordon

Activity

  1. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2017-04-06 16:08:57 UTC

    I added

    "colors": {
    "CMSToolBarButtonBackgroundHover": "red"
    }

    to a theme mixin and attached to the mouse hover event like this:

    private void Button_MouseHover(object sender, EventArgs e)
    {
    ((Button)sender).BackColor = System.Drawing.Color.FromName("@CMSToolBarButtonBackgroundHover");
    }

    It works here. I also tried to assign a BackColor to the button to something different than the default. Can you reproduce in a small test case?

    Thanks,

    Luca

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GeneralQuestions, how-tos and everything else.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions