Combobox View & Windows 7 Aero

Sep 13, 2010 at 9:38 AM

Hi there!

I found out that the ComboBox-View looks bad on Windows 7 (Aero design) - there is not enough room for the dropdown button.

See screenshot: http://img820.imageshack.us/img820/9580/frmsample14201009131002.jpg   - this is FrmSample14 taken from the last source-code version.

What can I do to make it look more "normally"? :)

Thanks a lot for suggestions,

Anne

 

Coordinator
Sep 13, 2010 at 12:34 PM

Just some brainstorming:

AFAIK, dropdown is drawn with a custom control. So probably that custom control for some reason is not drawing correctly the dropdown button. You could try investigating that and try to fix that in Win7

Sep 13, 2010 at 1:16 PM

Thanks, that was a good starting point!
I found out that the area that is passed to the OnDraw() method of class DevAge.Drawing.VisualElements.DropDownButtonThemed is only 7 points wide.

If I move the X position of the area 8 points to the left and extend the width by 9 points, I get the correct size of the dropdown button.
I think the calculation must be somewhere inside VisualElementBase.GetDrawingArea, but I couldn't find the exact line of code until now.

Coordinator
Sep 14, 2010 at 7:31 AM

Hey, great news.

This is exactly what should have been happening - for some reason on windows 7 the width is calculated as much smaller.

If you could find a place where that width is calculated, we could do some testing and try understand why on WinXP the size is calculated correctly, and on Win7 incorrectly.

As a last resort we could, of course, just add an if statement to that place, and say if this is win XP, just make the button a bit bigger, else just calculate as previously. I would really not like to do that, but if we don't find anything in the code, this would be a possible solution

Sep 14, 2010 at 7:54 AM
Edited Sep 14, 2010 at 12:29 PM

O.k. I found the exact position:  Method OnMeasureContent() of class DropDownButtonThemed.

The exact line inside of this method says

    return GetRenderer(GetBackgroundElement()).GetPartSize(measure.Graphics, ThemeSizeType.True);

The GetRenderer() method returns a System.Windows.Forms.VisualStyles.VisualStyleRenderer object, the constructor parameter is a VisualStyleElement with ClassName "COMBOBOX".
The GetPartSize method returns the wrong size (width = 7, height = 21)

So, can we influence the result of the GetPartSize() method somehow or should we include the fix into the OnMeasureContent() method of DropDownButtonThemed?

Edit: oh and I forgot that not only the width is wrong, but also the position (a little bit). If I do a hack only to fix the width, it looks like this: http://img137.imageshack.us/img137/5339/frmsample14201009141423.jpg

Aug 19, 2011 at 1:10 PM

Has there been any progress on this?

 

I'm wary of just adding some conditional code that checks the OS before tweaking the return value here...

Aug 19, 2011 at 2:47 PM

Posted on stackoverflow about the GetPartSize() bug:

http://stackoverflow.com/questions/7123303/suspected-bug-insystem-windows-forms-visualstyles-visualstylerenderer-getpartsize

Aug 20, 2011 at 6:35 PM

I ended up inserting the hack, checking the operating system and if Vista/Win7, changing the width and the position of the drop down button.

It really is an awful hack but I had no better idea :(

Aug 22, 2011 at 9:13 AM

@AnnX: Thanks, I've done the same thing, well - I'm returning a size of 15x16 for Vista/Win7 - which looks correct as we use a drop down style of "DropDownList".