c# - Multiple text format in a RichTextBox -
suppose there 2 lines. red line. blue line. can with.
you use:
void appendtext(richtextbox box, color color, string text) { int start = box.textlength; box.appendtext(text); int end = box.textlength; // textbox may transform chars, (end-start) != text.length box.select(start, end - start + 1); box.selectioncolor = color; // set box.selectionbackcolor, box.selectionfont, etc... box.selectionlength = 0; // clear }
and then
appendtext(rtb, color.red, "line1"); appendtext(rtb, color.blue, "line2");
Comments
Post a Comment