Multiple font setups for radLabel

4 posts, 1 answers
  1. Michael Marr
    Michael Marr avatar
    3 posts
    Member since:
    Sep 2009

    Posted 16 Feb 2010 Link to this post

    In my application I would like to set font for all labels via themes, which work great.
    Most labels sit next to controls which are set to bold.

    But as I was adding more labels I noticed that some labels that I have been adding should not be bold, should be using the same font type that the rest of the labels do, but should not be set to bold.

    I have tried several things, but any change to font in code is overwritten by the theme.
    I have tried looking at setting conditions in the theme, but radlabelelement has nothing useful i can bank on.

    Thank you,
  2. Michael Marr
    Michael Marr avatar
    3 posts
    Member since:
    Sep 2009

    Posted 16 Feb 2010 Link to this post

    I found the answer for this:

    I created a second theme, based on a post I found in these forums. The post said to use, ThemeResolutionService.GetRegisteredControlStyleBuilder which I got working but I must say the documentation on the method lacks. Maybe for many it is obvious what should go in all parameters but it was not for me,

    1) the first parameter is the element name you wish to get the style for, my case: typeof(RadLabel).FullName,
    2) the second parameter I thought was tricky, as the example provided in the post does not reference how to get it just gives an example of one, I spend a very long time trying out different things, the method i found to get it was,
    either user an existing variable or a new in brackets (new RadLabel()).RootElement.Gettype().FullName
    This can be applied to any element,
    since the full name from my example is "Telerik.WinControls.UI.RadLabel+RadLabelRootElement" seemed easier to use gettype rather than typeof(


    Problem with this solution is that I need 2 xml files for label theme rather than just one, and a good naming convention so not to hardcode full names,.

    Would be nice if there would be a better solution rather than a 2 xml file one I found.




  3. UI for WinForms is Visual Studio 2017 Ready
  4. Answer
    Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 19 Feb 2010 Link to this post

    Hi Michael Marr,

    Thank you for writing. Actually, if you set the font for particular RadLabels at run-time with code, it overrides the application theme settings:

    private void Form1_Load(object sender, EventArgs e)
    {
        ((TextPrimitive)this.radLabel3.LabelElement.Children[2].Children[1]).Font = new Font("Ariel", 12, FontStyle.Regular);
    }

    Let me know if you still experience any difficulties with this.

    Kind regards,
    Martin Vasilev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Michael Marr
    Michael Marr avatar
    3 posts
    Member since:
    Sep 2009

    Posted 19 Feb 2010 Link to this post

    Thank you for your reply.

    For my purposes this is perfect. My goal was just to have some fonts not be bold, while maintaining the use of themes and no hard coded look and feel.
    For more complicated solutions in which to have different fonts, (font type, size etc), while maintaining theme settings(all coming from the xml theme files) the 2 theme approach seems to be the only way.
    This answer also provided insight on a different question i had, on how to query at run time for the applied theme components.

    Thank you
Back to Top