Text to image (regex and richtextbox)
Hi All.
I'm writing a little console application to convert text to image and faced with a problem:
My solution gets text as parameter, then formats text in the richtexbox and draws it in the Graphics element.
And I need to use simple tags such as < b >, < i> , < f =...> etc.
The problem appears when I'm trying to use Regex.Replace method on the formatted richtextbox text. This method removes all
formatting and sets font to the default. I'm newbe in C# and don't see any solution except read text character by character, store indexes
of substrings which have to be formatted, remove tags from text by editing string and format text by stored indexes.
But maybe there is a normal way, to do it via Regexes?
OlegPosted Nov 3, 2009, 5:30 AM
OlegPosted Nov 3, 2009, 4:22 AM
Regex fontbold = new Regex(@"(< b>)(.*?)(< /b>)", RegexOptions.IgnoreCase);
Regex removefontboldtags = new Regex(@"(< b>)|(< /b>)", RegexOptions.IgnoreCase);
MatchCollection mc = fontbold.Matches(richTextBox1.Text);
for (int i = 0; i < mc.Count; i++)
{
richTextBox1.Select(mc[i].Index, mc[i].Length);
richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont.Name,richTextBox1.SelectionFont.Size,FontStyle.Bold);
}
It is ok, I have formatted text. Then I want to remove bold tag from text:
richTextBox1.Text = removefontboldtags.Replace(richTextBox1.Text,"");
And all fonts is set to default.
Kirtan PatelPosted Nov 3, 2009, 3:55 AM
Explain me your scenario in more detail and post your code which you are using in your program
friend ,post code in proper alignment please :)