How to set a black background and white text

7 posts, 2 answers
  1. Bart
    Bart avatar
    7 posts
    Member since:
    Apr 2016

    Posted 25 Apr Link to this post

    Hi,

    I'm trying to get the richtexteditor to display white text on a black background. (That's a requirement for us).

    Simply setting the back and forecolors doesn't really work well;

    _viewer.BackColor = Color.Black;
    _viewer.ForeColor = Color.White;
    _viewer.RichTextBoxElement.BackColor = Color.Black;
    _viewer.RichTextBoxElement.ForeColor = Color.White;

    I have also tried to change the paragraphs, but that still leaves a white paper, with paragraphs with  black background.

    _viewer.ChangeParagraphBackground(Color.Black);
    var documentEditor = new RadDocumentEditor(_viewer.Document);
    documentEditor.ChangeForeColor(Color.White);
    documentEditor.ChangeParagraphBackground(Color.Black);
    _viewer.Document.Selection.Clear();

     

    Any advice on how I can set it up ?

     

     

  2. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 27 Apr Link to this post

    Hi Bart,

    Thank you for writing.

    Could you please try setting the BackColor property along with calling the ChangeTextForeColor method of the editor:
    this.radRichTextEditor1.RichTextBoxElement.BackColor = Color.Black;
    this.radRichTextEditor1.ChangeTextForeColor(Color.White);

    I am also sending you a screenshot showing the result on my end.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Bart
    Bart avatar
    7 posts
    Member since:
    Apr 2016

    Posted 28 Apr in reply to Hristo Merdjanov Link to this post

    Hi Hristo,

    I tried this, but to no avail.

    The result can be seen in the Telerik.png file (what we need is in other.png).

    var rtfProvider = new RtfFormatProvider();
    viewer.Document = rtfProvider.Import(CleanupRtf(value));
    viewer.RichTextBoxElement.BackColor = Color.Black;
    viewer.ChangeTextForeColor(Color.White);

  5. Answer
    Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 28 Apr Link to this post

    Hello Bart,

    Thank you for writing.

    RadRichTextEditor is a complex control and if you import a document to it this changes the layout hierarchy. The styles need to be applied to the control as well as the page. 

    This can be achieved by modifying the theme you are using. I am sending you attached a screenshot showing the settings which need to be modified as well as a sample project using a single XML component for RadRichTextEditor. You can also check the following documentation resources: Themes, Visual Style Builder, RadThemeManager.

    I hope this helps. Please let me know if you need further assistance.

    Regards,
    Hristo Merdjanov
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Bart
    Bart avatar
    7 posts
    Member since:
    Apr 2016

    Posted 29 Apr in reply to Hristo Merdjanov Link to this post

    Hi Hristo,

    thanks for this. It is much better.

    I've corrected it to:

    private void Viewer_DocumentChanged(object sender, EventArgs e)
    {
        viewer.RichTextBoxElement.Document.Selection.SelectAll();
        viewer.RichTextBoxElement.ChangeTextForeColor(Color.White);
        viewer.RichTextBoxElement.Document.Selection.Clear();
     }

    It still doens't select the headers/footers for the colors.

  7. Answer
    Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 29 Apr Link to this post

    Hi Bart,

    Thank you for writing back.

    If I understand correctly you are having an issue with the text color of the headers and footers after you import the RTF document.

    In order to change their fore color, you would need to do something similar to changing the color of the text of the main document. Please check my code snippet below: 
    private void radRichTextEditor1_DocumentChanged(object sender, EventArgs e)
    {
        this.radRichTextEditor1.RichTextBoxElement.Document.Selection.SelectAll();
        this.radRichTextEditor1.RichTextBoxElement.ChangeTextForeColor(Color.White);
        this.radRichTextEditor1.RichTextBoxElement.Document.Selection.Clear();
     
        RadDocumentEditor headerEditor = new RadDocumentEditor(this.radRichTextEditor1.Document.Sections.First.Headers.Default.Body);
        this.radRichTextEditor1.Document.Sections.First.Headers.Default.Body.Selection.SelectAll();
        headerEditor.ChangeForeColor(Color.White);
     
        RadDocumentEditor footerEditor = new RadDocumentEditor(this.radRichTextEditor1.Document.Sections.First.Footers.Default.Body);
        this.radRichTextEditor1.Document.Sections.First.Footers.Default.Body.Selection.SelectAll();
        footerEditor.ChangeForeColor(Color.White);
    }

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  8. Bart
    Bart avatar
    7 posts
    Member since:
    Apr 2016

    Posted 29 Apr in reply to Hristo Merdjanov Link to this post

    Hi Hristo,

    This works. thanksa  lot.

Back to Top
UI for WinForms is Visual Studio 2017 Ready