Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4616716
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:01:21+00:00 2026-05-22T02:01:21+00:00

I am making a custom ComboBox, inherited from Winforms’ standard ComboBox. For my custom

  • 0

I am making a custom ComboBox, inherited from Winforms’ standard ComboBox. For my custom ComboBox, I set DrawMode to OwnerDrawFixed and DropDownStyle to DropDownList. Then I write my own OnDrawItem method. But I ended up like this:

Standard vs Custom ComboBoxes

How do I make my Custom ComboBox to look like the Standard one?


Update 1: ButtonRenderer

After searching all around, I found the ButtonRenderer class. It provides a DrawButton static/shared method which — as the name implies — draws the proper 3D button. I’m experimenting with it now.


Update 2: What overwrites my control?

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.

Here’s the 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 >= 0 Then
    TextToDraw = _DataSource.ItemText(e.Index)
  End If
  If TextToDraw.StartsWith("---") Then TextToDraw = StrDup(3, ChrW(&H2500)) ' U+2500 is "Box Drawing Light Horizontal"
  If (e.State And DrawItemState.ComboBoxEdit) > 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

And here’s the result:

Overwritten ButtonRenderer

Replacing Me.Parent.CreateGraphics with e.Graphics got me this:

Clipped ButtonRenderer

And doing the above + replacing Me.ClientRectangle with e.Bounds got me this:

Shrunk ButtonRenderer

Can anyone point me whose Graphics I must use for the ButtonRenderer.DrawButton method?

PS: The bluish border is due to my using PushButtonState.Default instead of PushButtonState.Normal


I Found An Answer! (see below)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:01:22+00:00Added an answer on May 22, 2026 at 2:01 am

    I forgot where I found the answer… I’ll edit this answer when I remember.

    But apparently, I need to set the Systems.Windows.Forms.ControlStyles flags. Especially the ControlStyles.UserPaint flag.

    So, my New() now looks like this:

    Private _ButtonArea as New Rectangle
    
    Public Sub New()
      ' This call is required by the designer.
      InitializeComponent()
      ' Add any initialization after the InitializeComponent() call.
      MyBase.SetStyle(ControlStyles.Opaque Or ControlStyles.UserPaint, True)
      MyBase.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
      MyBase.DropDownStyle = ComboBoxStyle.DropDownList
      ' Cache the button's modified ClientRectangle (see Note)
      With _ButtonArea
        .X = Me.ClientRectangle.X - 1
        .Y = Me.ClientRectangle.Y - 1
        .Width = Me.ClientRectangle.Width + 2
        .Height = Me.ClientRectangle.Height + 2
      End With
    End Sub
    

    And now I can hook into the OnPaint event:

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
      If Me.DroppedDown Then
        ButtonRenderer.DrawButton(Me.CreateGraphics, _ButtonArea, VisualStyles.PushButtonState.Pressed)
      Else
        ButtonRenderer.DrawButton(Me.CreateGraphics, _ButtonArea, VisualStyles.PushButtonState.Normal)
      End If
      MyBase.OnPaint(e)
    End Sub
    

    Note: Yes, the _ButtonArea rectangle must be enlarged by 1 pixel to all directions (up, down, left, right), or else there will be a 1-pixel ‘perimeter’ around the ButtonRenderer that shows garbage. Made me crazy for awhile until I read that I must enlarge the Control’s rect for ButtonRenderer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom combobox ( MyComboBox ) defined in my code (by making
Does making custom roms involve the same skill set as making apps? Are they
I am making custom buttons for my app and want to set the font
Hi im making a custom Textbox i got everty thing working but how do
I am making an application that does some custom image processing. The program will
Does anybody know the logic behind making DataSourceSelectArguments sealed? I've implemented a custom DataSource
I'm making custom events for C# and sometimes it isn't working. This is how
I am making custom NSScrollers for use in NSScrollView. But when any of the
What is the process behind making custom widgets (using Qt) that don't look...well...ugly? I
This is a question on making custom fields in Django. I'm making a field

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.