rtb formatting problems
-
I have been trying for a couple of days with no success at formatting some text in a rtb control. I will be entering something like this on each line: "username: the chat message" I want "username: " to be bold for example. All that ever happens is that EVERYTHING is turned bold, or only the first instance of "username: ", the rest ignored. Does anyone know what the best way to do this is? Cheers, Ben.
-
I have been trying for a couple of days with no success at formatting some text in a rtb control. I will be entering something like this on each line: "username: the chat message" I want "username: " to be bold for example. All that ever happens is that EVERYTHING is turned bold, or only the first instance of "username: ", the rest ignored. Does anyone know what the best way to do this is? Cheers, Ben.
Well you have to select "username:" There is a function Select(start, length) for the RichTextBox. In this case rtfbox.Select(0, 9); Then you can set the "SelectionFont": rtfbox.SelectionFont = new Font(rtfbox.Font, FontStyle.Bold); The username: should be bold. Regards, Ingo
------------------------------ PROST Roleplaying Game War doesn't determine who's right. War determines who's left.
-
I have been trying for a couple of days with no success at formatting some text in a rtb control. I will be entering something like this on each line: "username: the chat message" I want "username: " to be bold for example. All that ever happens is that EVERYTHING is turned bold, or only the first instance of "username: ", the rest ignored. Does anyone know what the best way to do this is? Cheers, Ben.
-
Well you have to select "username:" There is a function Select(start, length) for the RichTextBox. In this case rtfbox.Select(0, 9); Then you can set the "SelectionFont": rtfbox.SelectionFont = new Font(rtfbox.Font, FontStyle.Bold); The username: should be bold. Regards, Ingo
------------------------------ PROST Roleplaying Game War doesn't determine who's right. War determines who's left.
Thanks, but that still only does one instance of the term - I think it's finding the first instance and applying it to that over and over again - is there a way to find a string's position searching from the end instead of the beginning at all? -- modified at 6:24 Thursday 3rd August, 2006
-
Thanks, but that still only does one instance of the term - I think it's finding the first instance and applying it to that over and over again - is there a way to find a string's position searching from the end instead of the beginning at all? -- modified at 6:24 Thursday 3rd August, 2006
SoftcodeSoftware wrote:
Thanks, but that still only does one instance of the term - I think it's finding the first instance and applying it to that over and over again - is there a way to find a string's position searching from the end instead of the beginning at all?
You can search the position of a string: str.IndexOf("username:"); or str.LastIndexOf("username:"); So you can search every part of the string you want bold and then select it and set it bold like in the first answer I gave. example: string searchstr[] = new string[]; searchstr[0] = "username:"; for (int i = 0; i < searchstr.Length; i++) { rtfbox.Select(rtfbox.Text.IndexOf(searchstr[i]), searchstr[i].Length); ... } Regards, Ingo -- modified at 6:57 Thursday 3rd August, 2006
------------------------------ PROST Roleplaying Game War doesn't determine who's right. War determines who's left.
-
SoftcodeSoftware wrote:
Thanks, but that still only does one instance of the term - I think it's finding the first instance and applying it to that over and over again - is there a way to find a string's position searching from the end instead of the beginning at all?
You can search the position of a string: str.IndexOf("username:"); or str.LastIndexOf("username:"); So you can search every part of the string you want bold and then select it and set it bold like in the first answer I gave. example: string searchstr[] = new string[]; searchstr[0] = "username:"; for (int i = 0; i < searchstr.Length; i++) { rtfbox.Select(rtfbox.Text.IndexOf(searchstr[i]), searchstr[i].Length); ... } Regards, Ingo -- modified at 6:57 Thursday 3rd August, 2006
------------------------------ PROST Roleplaying Game War doesn't determine who's right. War determines who's left.
Excellent, thanks, Im all sorted now :)