I have text with “wild characters”, like “@ARed text” where @A is sign for red colour. I need to replace @A with some function (or something like that) so wherever there is @A in text, text font becomes red coloured. I have several colours (@B, @C…) so for every of them I need to do same thing, just different colour.
So, “@ASome red text @BSome green text” would be coloured red and green respectively (can’t find text colouring here on SO).
Any ideas?
Thanks.
What I would do is capture the
PreRenderevent of the label and test forYourLabel.Text.Substring(0, 1)and if that is the at-sign (@) then conditionally test (I’d use a switch) the second character. You can then get the rest of the string without the@Aand set the Label’s text then, and format according to the property characters.Something like this:
Edit: this is untested code, but you should get the general idea of the logic.