c# - Richtextbox prepend new text with color -
i have used richtextbox display logs in winforms.
language used c#.
the software used inserting data of bank branches , after start of new branch want display text new color.
i have seen link color different parts of richtextbox string , implemeted successfully.
my problem want prepend new line instead of append. new line displayed on top.
i able changing code box.text=datetime.now.tostring("dd-mm-yyyy-hh-mm-ss") + ": " + text + box.text
but color changing entire text.
this procedure used append
box.selectionstart = box.textlength; box.selectionlength = 0; box.selectioncolor = color; box.appendtext(datetime.now.tostring("dd-mm-yyyy-hh-mm-ss") + ": " + text); box.selectioncolor = box.forecolor;
this have done:
box.text=datetime.now.tostring("dd-mm-yyyy-hh-mm-ss") + ": " + text + box.text; box.selectionstart = 0; box.selectionlength = text.length; box.selectioncolor = color;
but not working.
1) never directly change text
property of formatted richttextbox
2) append use rtb.appendtext
function
3) insert @ other position p
, including beginning use this:
rtb.selectionstart = s; // set cursor target position rtb.selection.length = 0; // nothing selected, yet rtb.selectedtext = yournewtext; // inserts new text
now can add formatting want:
rtb.selectionstart = s; // prepare new formatting.. rtb.selectionlength = yournewtext.length; //.. selecting text rtb.selectioncolor = color.blue; // and/or whatever want do.. ...
Comments
Post a Comment