Resources » Code Snippets » Winforms Controls

Changing font in RichTextBox's Text


Posted Date: 11-Sep-2007  Last Updated:   Category: Winforms Controls    
Author: Member Level: Gold    Points: 10


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);
}



Did you like this resource? Share it with your friends and show your love!

Responses to "Changing font in RichTextBox's Text"

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

Feedbacks      

Post 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    ahmed
    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India