Best way to manipulate RichText in C #?

I need to create and copy some RichText to the clipboard with standard "formatting", for example, bold / italics, indentation, etc. The way I am doing this now seems a bit inelegant ... I create a RichTextBox element and apply my formatting as follows:

RichTextBox rtb = new RichTextBox();
Font boldfont = new Font("Times New Roman", 10, FontStyle.Bold);
rtb.Text = "sometext";
rtb.SelectAll()
rtb.SelectionFont = boldfont;
rtb.SelectionIndent = 12;

There should be a better way, but after several hours of searching, I could not come up with anything better. Any ideas?

Edit: RichTextBox (rtb) is not displayed / drawn anywhere on the form. I just use an object to format a RichText.

+5
source share
6 answers

richtextbox, , . , , "".

+3

, - , . , ... "", Winforms - , , . . , - .

+3

, "":)

public static RichTextBox Set(this RichTextBox rtb, Font font, string text)
{               
    rtb.Text = text;
    rtb.SelectAll();
    rtb.SelectionFont = font;
    rtb.SelectionIndent = 12;
    return rtb;
}

:

someRtb.Set(yourFont, "The Text").AndThenYouCanAddMoreAndCHainThem();

: , . Hrm, , , Non Rtb.

+2

richtextbox .

RichTextBox rtb = new RichTextBox();
rtb.SuspendLayout();
//richtext processing goes here...
rtb.Dispose();

richtextbox richtext. Microsoft , .: -)

+1

, - , stackoverflow rtf html. , html, , html, rtf.

Rtf HTML

0

All Articles