Changing font in RichTextBox's Text


This article helps to clearing the concept of how to Changing font in RichTextBox's Text

This code sample shows how to find out and changing the font of a single word in RichTextBox.



private void FindAndChangeFont(RichTextBox ptxtRichTextBox, string pstrFind)
{
try
{
if(ptxtRichTextBox != null)
{
System.Drawing.Font fntFont = new Font("Verdana",10f, System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,178,false);
int i = ptxtRichTextBox.Find(pstrFind);
int j = pstrFind.Length;
ptxtRichTextBox.Select(i, j);
ptxtRichTextBox.SelectionFont = fntFont;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}

//Calling above fucntion
private void button6_Click(object sender, System.EventArgs e)
{
richTextBox1.Text = "www.dotnetspider.com";
string strFind = "dotnetspider";
FindAndChangeFont(richTextBox1, strFind);
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: