RichtextBox Problem
-
how are you Dudes ? I have one probelm in my application i need to display multiple lines in richtextbox but each line has its own attributes of new font , size and new color how can i manage this in the richtextbox knowing that i succeeded to do that using the following code but there was a small probelm .
int index = richtextbox1.Find(string message , 0 , message.length); richtextbox1.select(index , 0 , message.length); richtextbox1.selectionFont = new font(font attributes goes here of the new font); richtextbox1.selectionColor = Color.Blue // for example
But with the above code it will certainly manage every new written line with its new font and color attributes but if i entered two or more sentences similar to each other the first one of them will be only changed and the newly entered message which is similar to the previous will have the defaul color and font. So the question is : How can i inset multiple lines of texts each of which with different font and color attributes. Miss With The Best And Die Like The Rest -
how are you Dudes ? I have one probelm in my application i need to display multiple lines in richtextbox but each line has its own attributes of new font , size and new color how can i manage this in the richtextbox knowing that i succeeded to do that using the following code but there was a small probelm .
int index = richtextbox1.Find(string message , 0 , message.length); richtextbox1.select(index , 0 , message.length); richtextbox1.selectionFont = new font(font attributes goes here of the new font); richtextbox1.selectionColor = Color.Blue // for example
But with the above code it will certainly manage every new written line with its new font and color attributes but if i entered two or more sentences similar to each other the first one of them will be only changed and the newly entered message which is similar to the previous will have the defaul color and font. So the question is : How can i inset multiple lines of texts each of which with different font and color attributes. Miss With The Best And Die Like The RestHi Ive not really used richtextboxes, but looking at your code, i think you just need to change the start position in richtextbox1.Find, and then use a loop:
int pos = 0; while(pos < richtextbox1.TextLength) { // search for text at last position and stop if none found int index = richtextbox1.Find(message, pos, RichTextBoxFinds.None); if(index == -1) break; richtextbox1.Select(index, message.Length); richtextbox1.SelectionFont = new Font(...); richtextbox1.SelectionColor = Color.Blue; // move to end of found text pos = index + message.Length; }
Hope this helps Philip Cole