formatting in a richtextbox

G

Guest

hi,

i have a richtextbox in my app. when a button is disabled, the richtextbox
control should say "The button is now disabled". only the word disabled
should be emboldened. how do i make only the word bold?

my code so far is

if (Button1.Enabled = false)
{
richTextBox1.Text = "The button is now disabled";
}
 
C

Cathal Connolly [C# MVP]

You can either use a combination of SelectedText and SelectionFont e.g.
richTextBox1.SelectedText="The button is now ";
richTextBox1.SelectionFont=New
Font(currentFont.FontFamily,currentFont.Size,FontStyle.Bold);
richTextBox1.SelectedText="disabled";

or else pipe in the RTF characters directly e.g.
richTextBox1.Rtf = @"{\rtf1\ansi The button is now \b disabled\b0.}";

Cathal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top