Chanage page background color in print layout

4 posts, 1 answers
  1. Mihajlo
    Mihajlo avatar
    38 posts
    Member since:
    Aug 2018

    Posted 21 Aug 2018 Link to this post

    In demo project if I set radRichTextEditor1.RichTextBoxElement.BackColor = Color.Aqua in constructor I see the background color changed in web layout. But in print layout only the color of the background behind the pages is changed. How to change the color of the pages too?
  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    2823 posts

    Posted 22 Aug 2018 Link to this post

    Hi Mihajlo,

    The page elements are created dynamically and they cannot be accessed in the code. What you need to do is edit the theme in code and set the BackColor. Here is the code:
    public void SetBackColor()
    {
        this.radRichTextEditor1.RichTextBoxElement.BackColor = Color.Red;
        Theme theme = ThemeRepository.FindTheme("TelerikMetro");
     
        foreach (var styleGroup in theme.StyleGroups)
        {
            foreach (PropertySettingGroup settingGroup in styleGroup.PropertySettingGroups)
            {
                if (settingGroup.Selector.Value == "Telerik.WinControls.RichTextEditor.UI.Page")
                {
                    foreach (PropertySetting property in settingGroup.PropertySettings)
                    {
                        if (property.Name == "BackColor")
                        {
                            property.Value = System.Drawing.Color.Red;
                        }
                    }
                }
                if (settingGroup.Selector.Value == "Telerik.WinControls.RichTextEditor.UI.HeaderFooterContainer")
                {
                    foreach (PropertySetting property in settingGroup.PropertySettings)
                    {
                        if (property.Name == "OverlayColor")
                        {
                            property.Value = System.Drawing.Color.Red;
                        }
                    }
                }
            }
        }
     
    }

    This will work with themes that have BackColor set to other than white (White is the default color and there are no explicit settings for it). With the themes where the color is white, you can edit the theme in Visual Style Builder and set the color, but this is a complex because you need to export and edit the predefined theme and then load it in your project. If you let me know what theme you want to use I will prepare an example that shows this as well.

    I am looking forward to your reply.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Mihajlo
    Mihajlo avatar
    38 posts
    Member since:
    Aug 2018

    Posted 22 Aug 2018 in reply to Dimitar Link to this post

    Thanks for the reply. It's true, I actually want white background. For now I'll go with ControlDefault theme. If I ever need theme functionality, I'll bear this code in mind.

    Maybe these background colors for dynamic controls should take values from parent controls, where appropriate? Or introduce some new property, PageBackgroundColor, in this special case? 

  4. Dimitar
    Admin
    Dimitar avatar
    2823 posts

    Posted 23 Aug 2018 Link to this post

    Hi Mihajlo,

    Indeed there should be an easier way to change the BackColor. This is why I have logged a feature request for this in our Feedback Portal. You can track its progress, subscribe to status changes and add your comment to it here. I have also updated your Telerik Points.

    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top