I’m creating a custom ComboBox that allows the user to select a date; the calendar display is localized making the built-in DateTimePicker undesirable [see here for more information]. I need the UI control to mirror the look and feel or the existing components. Here’s what I’ve tried and the problems I’ve encountered:
- Using a
TextBoxwith a drawnComboBoxbutton: I’ve tried usingComboBoxRenderer.DrawDropDownButtonbut the look and feel does not mirror the existing UI controls. In particular we don’t haveApplication.EnableVisualStyles()so the buttons have a Windows 98 look and feel.ComboBoxRendererdraws a glossy grey button. - Using a
ComboBoxand aToolStripDropDownto contain the calender control: the button has the correct look and feel but I cannot hide the drop down box completely. Even though theToolStripControlHostis effectively hiding the drop down box, when I click the button, I can see the drop down box being rendered just before theToolStripDropDownis displayed. I’ve tried workarounds that effectively disable the drop down box but the button, as you would expect, does not maintain the desired visual state of being pressed (and drawing the button brings me back to the problem in the above point).
Setting the height of the drop down box to zero inOnMeasureItemdoes not work; though I suppose I could make the drop down box the same height as my calendar UI selector so that the rendering doesn’t look particularly bad.
Are there existing mechanisms to get the behaviour I need: a TextBox that displays the selected date with a drop down arrow button that, when clicked, displays a calendar UI selection component. The calendar component already exists and the button must look like the existing Windows 98 look and feel ComboBox buttons.
Thank you for your time and assistance.
I wasn’t able to find a clear solution so I’ve implemented a workaround: I’ve taken a screenshot of the Windows 98 style button in the normal and pressed state (there isn’t a hover state) and added them as an image resource (in a resx file). I then draw the image according to the current user interaction. This has several consequences including: any changes to the visual style will not be seamless and if the control height is changed, the button won’t resize like other
ComboBoxinstances.