0

I wanna to make my bold,italic,underline buttons work with eachother in richtextbox. I found an example, but its in c#. Help pls, how its works in c++:

if(e.Button==toolBarButton1)
{
    int fStyle = (int)FontStyle.Bold + (int)FontStyle.Italic;
    FontStyle f = (FontStyle)fStyle;
    richTextBox1.SelectionFont = 
        new Font(richTextBox1.Font.Name, richTextBox1.Font.Size, f);
}

my version, I want to remake it

     if ( RichTextBox1->SelectionFont != nullptr )
   {
      System::Drawing::Font^ currentFont = RichTextBox1->SelectionFont;
      System::Drawing::FontStyle newFontStyle;
      if ( RichTextBox1->SelectionFont->Bold == true )
      {
         newFontStyle = FontStyle::Regular;
      }
      else
      {
         newFontStyle = FontStyle::Bold;
      }
      RichTextBox1->SelectionFont = gcnew System::Drawing::Font( currentFont->FontFamily,currentFont->Size,newFontStyle );
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
user2227430
  • 71
  • 1
  • 1
  • 6

1 Answers1

0

If you want a direct conversion of the C# to C++/CLI, just use:

if (e->Button == toolBarButton1)
{
    int fStyle = safe_cast<int>(FontStyle::Bold) + safe_cast<int>(FontStyle::Italic);
    FontStyle ^f = safe_cast<FontStyle^>(fStyle);
    richTextBox1->SelectionFont = gcnew Font(richTextBox1::Font->Name, richTextBox1::Font::Size, f);
}
Dave Doknjas
  • 6,394
  • 1
  • 15
  • 28