title: How to make a custom ComboBox (OwnerDrawFixed) looks 3D like the standard ComboBox?
body: <p>I am making a custom ComboBox, inherited from Winforms' standard ComboBox. For my custom ComboBox, I set <code>DrawMode</code> to <code>OwnerDrawFixed</code> and <code>DropDownStyle</code> to <code>DropDownList</code>. Then I write my own <code>OnDrawItem</code> method. But I ended up like this:</p>
  <p><img src="https://i.stack.imgur.com/R7gUZ.png" alt="Standard vs Custom ComboBoxes" /></p>
  <p>How do I make my Custom ComboBox to look like the Standard one?</p>
  <hr />
  <h3>Update 1: ButtonRenderer</h3>
  <p>After searching all around, I found the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.buttonrenderer.aspx" rel="noreferrer"><code>ButtonRenderer</code> class</a>. It provides a <code>DrawButton</code> static/shared method which -- as the name implies -- draws the proper 3D button. I'm experimenting with it now.</p>
  <hr />
  <h3>Update 2: What overwrites my control?</h3>
  <p>I tried using the Graphics properties of various objects I can think of, but I always fail. Finally, I tried the Graphics of the form, and apparently something is overwriting my button.</p>
  <p>Here's the code:</p>
  <pre><code>Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
    Dim TextToDraw As String = _DefaultText
    __Brush_Window.Color = Color.FromKnownColor(KnownColor.Window)
    __Brush_Disabled.Color = Color.FromKnownColor(KnownColor.GrayText)
    __Brush_Enabled.Color = Color.FromKnownColor(KnownColor.WindowText)
    If e.Index &gt;= 0 Then
      TextToDraw = _DataSource.ItemText(e.Index)
    End If
    If TextToDraw.StartsWith(&quot;---&quot;) Then TextToDraw = StrDup(3, ChrW(&amp;H2500)) ' U+2500 is &quot;Box Drawing Light Horizontal&quot;
    If (e.State And DrawItemState.ComboBoxEdit) &gt; 0 Then
      'ButtonRenderer.DrawButton(e.Graphics, e.Bounds, VisualStyles.PushButtonState.Default)
    Else
      e.DrawBackground()
    End If
    With e
      If _IsEnabled(.Index) Then
        .Graphics.DrawString(TextToDraw, Me.Font, __Brush_Enabled, .Bounds.X, .Bounds.Y)
      Else
        '.Graphics.FillRectangle(__Brush_Window, .Bounds)
        .Graphics.DrawString(TextToDraw, Me.Font, __Brush_Disabled, .Bounds.X, .Bounds.Y)
      End If
    End With
    TextToDraw = Nothing
    ButtonRenderer.DrawButton(Me.Parent.CreateGraphics, Me.ClientRectangle, VisualStyles.PushButtonState.Default)
  
    'MyBase.OnDrawItem(e)
  End Sub
  </code></pre>
  <p>And here's the result:</p>
  <p><img src="https://i.stack.imgur.com/YrUT1.png" alt="Overwritten ButtonRenderer" /></p>
  <p>Replacing <code>Me.Parent.CreateGraphics</code> with <code>e.Graphics</code> got me this:</p>
  <p><img src="https://i.stack.imgur.com/xKJdS.png" alt="Clipped ButtonRenderer" /></p>
  <p>And doing the above + replacing <code>Me.ClientRectangle</code> with <code>e.Bounds</code> got me this:</p>
  <p><img src="https://i.stack.imgur.com/oJhIH.png" alt="Shrunk ButtonRenderer" /></p>
  <p>Can anyone point me <em>whose Graphics</em> I must use for the <code>ButtonRenderer.DrawButton</code> method?</p>
  <p><em>PS: The bluish border is due to my using PushButtonState.Default instead of PushButtonState.Normal</em></p>
  <hr />
  <h2>I Found An Answer! <em>(see below)</em></h2>