This is a migrated thread and some comments may be shown as answers.

Font change in textbox

2 Answers 492 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
ankit
Top achievements
Rank 1
ankit asked on 24 Mar 2011, 11:50 AM
Hi,

In my project i need to change  font size and font family at runtime through code. Can anyone please tell me how can i do it?

Thanks 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Mar 2011, 07:03 AM
Hello,


You can change the ForeColor of RadTextBox control by changing the ForeColor  of its subelements RadTextBoxItem and FillPrimitive:

Code:
radTextBox1.TextBoxElement.TextBoxItem.ForeColor = Color.Red;         
((FillPrimitive)this.radTextBox1.TextBoxElement.Children[1]).ForeColor = Color.Red;

And here is the form, which discusses similar scenario:
BackColor



Regards,
Princy.
0
Ivan Petrov
Telerik team
answered on 25 Mar 2011, 11:11 AM
Hello ankit,

Thank you for writing.

You can change the font by assigning a Font variable to the Font property of RadTextBox. Consider the following code snippet:

public partial class Form1 : Form
{
   Font font;
 
   public Form1()
   {
      InitializeComponent();
 
      this.font = new Font("Arial", 14, FontStyle.Bold | FontStyle.Italic);
 
      this.radTextBox1.Font = this.font;
   }
}

Note that it is a good idea to have fonts created only once in your app, because the creation of a font is a heavy operation and can lead to memory leaks.

I hope this will help. If you have further questions, I would be happy to help.

 

Best wishes,
Ivan Petrov
the Telerik team
Tags
TextBox
Asked by
ankit
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ivan Petrov
Telerik team
Share this question
or