For the code below I Select an area in a textBox that I will Mark Red.
I will also change the Fontsize to 16 and make the selected text Bold
but are not sure what calls that is used for this.

this->richTextBox1->Select( 0, 10 );
this->richTextBox1->SelectionColor = Color::Red;

Recommended Answers

All 7 Replies

There's also a SelectionFont property:

this->richTextBox1->Select( 0, 10 );

Font^ current = this->richTextBox1->SelectionFont;

this->richTextBox1->SelectionColor = Color::Red;
this->richTextBox1->SelectionFont = gcnew Font (
  current->FontFamily, current->Size, FontStyle::Bold );

The only way I know is by using the System::Drawing namespace. It allows you to define brushes, and with it fonts, colors, text formatting(including bold).

System::Drawing::Brush^ testBrush = Brushes::Black;
//System::Drawing::Font::Bold
System::Drawing::Graphics::DrawString("Use this to draw a string", someFont, testBrush, somePoint);

You should be able to add the bold property to the brush somewhere(Not quite sure). Or perhaps even create a font, add the bold property to it, and use it as you were doing before.

Or just go with Narue's way, it's a bit easier. :)

I try to use this method I think.
I have put this code but the compiler says that "current" is an undeclared identifier.

this->richTextBox1->Select( 0, 10 );

Font^ current = this->richTextBox1->SelectionFont;

this->richTextBox1->SelectionColor = Color::Red;
this->richTextBox1->SelectionFont = gcnew Font (  current->FontFamily, current->Size, FontStyle::Bold );

There's also a SelectionFont property:

this->richTextBox1->Select( 0, 10 );

Font^ current = this->richTextBox1->SelectionFont;

this->richTextBox1->SelectionColor = Color::Red;
this->richTextBox1->SelectionFont = gcnew Font (
  current->FontFamily, current->Size, FontStyle::Bold );

Include the System:: Drawing(Remove the space) namespace at the start of your file, or write it like this: System:: Drawing::Font^(Once again, remove the space)

Thanks.. If I compile only the first line in this example it compiles fine but
when I add the second line, the compiler says that:
syntax error: identifier Font.
Wonder why that could be happening.

System::Drawing::Font^ current = this->richTextBox1->SelectionFont;

this->richTextBox1->SelectionFont = gcnew Font (  current->FontFamily, current->Size, FontStyle::Bold );

Include the System:: Drawing(Remove the space) namespace at the start of your file, or write it like this: System:: Drawing::Font^(Once again, remove the space)

Same thing. Unless you're opening the System::Drawing namespace, you need to qualify all instances of Font as System::Drawing::Font.

It worked when I put System:: Drawing:: Font like that but the strange thing is that I do open the System:: Drawing namespace so that was strange however why it didn´t work.
Thanks for help..

this->richTextBox1->SelectionFont = gcnew System::Drawing::Font (  current->FontFamily, 16, FontStyle::Bold );

Same thing. Unless you're opening the System::Drawing namespace, you need to qualify all instances of Font as System::Drawing::Font.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.