title: Is there a way to fix the text issue on a custom menu strip options in WinForm C++ when moving to one monitor to another?
body: <p>I did a lot of search and research and didn't find a answer for my probleam, so.. I made a custom Menu using WinForm C++, where we override the Renderer and OnPaint methods.
  Our application can move to one monitor to another and when we do that, the texts of the options on my Menu get corrupted.
  I don't have any idea or know if this has a solution. I'll be very thankfull if somebody can help me.</p>
  
  <p>Heres the menu right:<br>
  <a href="https://i.stack.imgur.com/6apoz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6apoz.png" alt="menu correct"></a></p>
  
  <p>And the Bug:<br>
  <a href="https://i.stack.imgur.com/L8KNQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L8KNQ.png" alt="Text corrupted"></a></p>
  
  <p><strong>MyRenderer.h</strong></p>
  
  <pre><code>    ref class MyRenderer: ToolStripProfessionalRenderer
      {
  
      protected:
  
      virtual void OnRenderToolStripBorder(System::Windows::Forms::ToolStripRenderEventArgs ^e) override
        {
  
         System::Drawing::SolidBrush^ brush = gcnew System::Drawing::SolidBrush(Color::FromArgb(static_cast&lt;System::Int32&gt;(static_cast&lt;System::Byte&gt;(0)), static_cast&lt;System::Int32&gt;(static_cast&lt;System::Byte&gt;(60)),static_cast&lt;System::Int32&gt;(static_cast&lt;System::Byte&gt;(107))));
  
         e-&gt;Graphics-&gt;FillRectangle(brush, e-&gt;ConnectedArea);
         Drawing::Rectangle rectBorder = Drawing::Rectangle(0, 1, e-&gt;AffectedBounds.Width-1, e-&gt;AffectedBounds.Height-2);
  
         Pen^ pen = gcnew Pen(brush, 2);
  
         e-&gt;Graphics-&gt;DrawRectangle(pen, rectBorder);
        }
      };
  </code></pre>
  
  <p><strong>MenuHover.h</strong></p>
  
  <pre><code>    public ref class MenuHover: ToolStripMenuItem
      {
      protected:
      virtual void OnPaint(PaintEventArgs ^e) override
      {
      if (this-&gt;Visible)
      {
          System::Drawing::SolidBrush^ brush = gcnew             System::Drawing::SolidBrush(Color::FromArgb(static_cast&lt;System::Int32&gt;(static_cast&lt;System::Byte&gt;(0)), static_cast&lt;System::Int32&gt;(static_cast&lt;System::Byte&gt;(60)), 
              static_cast&lt;System::Int32&gt;(static_cast&lt;System::Byte&gt;(107))));
  
          e-&gt;Graphics-&gt;FillRectangle(brush, e-&gt;ClipRectangle.X, e-&gt;ClipRectangle.Y, e-&gt;ClipRectangle.Width, e-&gt;ClipRectangle.Height+34);
  
          Drawing::Rectangle rect = Drawing::Rectangle(e-&gt;ClipRectangle.X, e-&gt;ClipRectangle.Y+5, e-&gt;ClipRectangle.Width, e-&gt;ClipRectangle.Height+34);
          StringFormat^ sf = gcnew StringFormat();
          sf-&gt;Alignment = StringAlignment::Center;
  
          e-&gt;Graphics-&gt;DrawString(this-&gt;Text, this-&gt;Font, Brushes::White, rect, sf);
      }
  
      if (this-&gt;Selected || this-&gt;Pressed)
      {
          System::Drawing::SolidBrush^ brush = gcnew System::Drawing::SolidBrush(Color::FromArgb(static_cast&lt;System::Int32&gt;(static_cast&lt;System::Byte&gt;(0)), static_cast&lt;System::Int32&gt;(static_cast&lt;System::Byte&gt;(42)), 
              static_cast&lt;System::Int32&gt;(static_cast&lt;System::Byte&gt;(82))));
  
          e-&gt;Graphics-&gt;FillRectangle(brush, e-&gt;ClipRectangle.X, e-&gt;ClipRectangle.Y, e-&gt;ClipRectangle.Width, e-&gt;ClipRectangle.Height);
  
          Drawing::Rectangle rect = Drawing::Rectangle(e-&gt;ClipRectangle.X, e-&gt;ClipRectangle.Y+5, e-&gt;ClipRectangle.Width, e-&gt;ClipRectangle.Height);
  
          StringFormat^ sf = gcnew StringFormat();
          sf-&gt;Alignment = StringAlignment::Center;
  
          e-&gt;Graphics-&gt;DrawString(this-&gt;Text, this-&gt;Font, Brushes::White, rect, sf);
         }
        }
      };
  </code></pre>
  
  <p><strong>MenuHoverItem.h</strong></p>
  
  <pre><code>    ref class MenuHoverItem: ToolStripMenuItem
      {
      protected:
      virtual void OnPaint(PaintEventArgs ^e) override
      {
      if (this-&gt;Visible)
      {
          System::Drawing::SolidBrush^ brush = gcnew System::Drawing::SolidBrush(Color::FromArgb(static_cast&lt;System::Int32&gt;(static_cast&lt;System::Byte&gt;(0)), static_cast&lt;System::Int32&gt;(static_cast&lt;System::Byte&gt;(42)), 
              static_cast&lt;System::Int32&gt;(static_cast&lt;System::Byte&gt;(82))));
  
          e-&gt;Graphics-&gt;FillRectangle(brush, e-&gt;ClipRectangle.X, e-&gt;ClipRectangle.Y, e-&gt;ClipRectangle.Width, e-&gt;ClipRectangle.Height);
          Drawing::Rectangle rect = Drawing::Rectangle(e-&gt;ClipRectangle.X+14, e-&gt;ClipRectangle.Y+1, e-&gt;ClipRectangle.Width, e-&gt;ClipRectangle.Height);
          StringFormat^ sf = gcnew StringFormat();
          sf-&gt;LineAlignment = StringAlignment::Center;
  
          e-&gt;Graphics-&gt;DrawString(this-&gt;Text, this-&gt;Font, Brushes::White, rect, sf);
      }
  
      if (this-&gt;Selected || this-&gt;Pressed)
      {
          System::Drawing::SolidBrush^ brush = gcnew System::Drawing::SolidBrush(Color::FromArgb(static_cast&lt;System::Int32&gt;(static_cast&lt;System::Byte&gt;(0)), static_cast&lt;System::Int32&gt;(static_cast&lt;System::Byte&gt;(60)), 
              static_cast&lt;System::Int32&gt;(static_cast&lt;System::Byte&gt;(107))));
  
          e-&gt;Graphics-&gt;FillRectangle(brush, e-&gt;ClipRectangle.X, e-&gt;ClipRectangle.Y, e-&gt;ClipRectangle.Width, e-&gt;ClipRectangle.Height-1);
          Drawing::Rectangle rect = Drawing::Rectangle(e-&gt;ClipRectangle.X+14, e-&gt;ClipRectangle.Y+1, e-&gt;ClipRectangle.Width, e-&gt;ClipRectangle.Height);
  
          StringFormat^ sf = gcnew StringFormat();
          sf-&gt;LineAlignment = StringAlignment::Center;
          e-&gt;Graphics-&gt;DrawString(this-&gt;Text, this-&gt;Font, Brushes::White, rect, sf);
         }
        }
      };
  </code></pre>
  
  <p>If theres a question like that, please send me a link and my I'm sorry if theres anything wrong, thanks for the help</p>