title: Prevent flickering when handling WM_PAINT in C#
body: <p>I am working on a set of UI Elements currently and the ComboBox is giving me a hard time.</p>
  
  <p>My goal is to paint a 1px border around the element which will change color when the mouse hovers over it.</p>
  
  <p>I used the <code>WndProc()</code> Method to react to the <code>WM_PAINT</code> Message and draw the border:</p>
  
  <pre><code>protected override void WndProc(ref Message m)
  {
          if (m.Msg == (int)WindowsMessages.Win32Messages.WM_PAINT)
          {
              base.WndProc(ref m);
              if (hovered || Focused)
              {
                  //Paint frame with hovered color when being hovered over
                  PaintHelper.PaintFrame(this, _frameColorHovered, _frameWidth);
              }
              else
              {
                  //Paint frame with standart color
                  PaintHelper.PaintFrame(this, _frameColor, _frameWidth);
              }
  
          }
          .
          .
          .
  }
  </code></pre>
  
  <p>Paint helper method looks as follows:</p>
  
  <pre><code>public static void PaintFrame(Control target, Color color, int frameWidth)
  {
          IntPtr dc = GetWindowDC(target.Handle);
          using (Graphics g = Graphics.FromHdc(dc))
          {
              using (Pen p = new Pen(color, frameWidth))
                  g.DrawRectangle(p, frameWidth / 2, frameWidth / 2, target.Width - frameWidth, target.Height - frameWidth);
          }
   }
  </code></pre>
  
  <p>So far so good but the border keeps flickering when the mouse moves out or inside of the the Elements bounds! I did some research but everyone uses the <code>UserPaint</code> flag which is not an option for me.</p>
  
  <p>So:
  Is there any way to remove the flickering without painting the whole control myself?</p>