Search code examples
c#activereports

In Active reports, how to give Characters one font size and for Numerics one font size in Richtextbox?


I am stuck with this issue since few hours :( Requirement is to display the dynamic data in textbox but the problem here is in the dynamic data characters should be of Gill Sans MT, 15pt and where ever Numerics(0,1,2..,9) come they should be Gill Sans MT, 20pt.

So i opted to use Richtextbox controll but unable to achieve the desired out put, code looks like

foreach (char c in richTextBox1.Text)
{
     if (c <= '9')
     {
         richTextBox1.SelectionFont = new Font("GillSansMT", 20);
     }
     else
     {
         richTextBox1.SelectionFont = new Font("GillSansMT", 15);
     }
}

Am trying to check each character in richtextbox, if suppose it is numeric by the virtue of above code am successful to find it out and its going in to the loop but the richTextBox1.SelectionFont is not working default its taking 10pt font size its not taking 20pt.

Need some assistance for this problem. Thanks in advance


Solution

  • You are using the SelectionFont to set the font but there is no selection. you need to use the SelectionStart and SelectionLength properties to set the selection then change its font. Also, I would not recommend creating the new Font in a loop. you should create the fonts outside the loop then reuse in the loop.

    hope this helps.
    http://activereports.grapecity.com