Thursday, January 8, 2009

Paint API on Vista

I was testing bunch of custom controls using Managed paint API on Windows Vista. Basically, managed and unmanaged paint API use native resources of the OS to paint controls, so if you run your controls on Windows XP you’ll get XP look and feel and if you run it on Vista, you get new vistaish look and feel, right? All control parts I’ve tested seems to work, but there is a catch! If you draw a disabled TextBox, it looks strange in Windows Vista, but looks right in XP :

VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Disabled);
renderer.DrawBackground(e.Graphics, ClientRectangle);
While this code looks fine in XP, it produces a flat blue textbox on Vista :

VistaPaintAPI-Normal VistaPaintAPI-Readonly

As far as I could tell, this is an issue with textbox only and other controls like buttons, etc render correctly in both OSes.

I wonder why?! From end-user’s perspective this doesnot look like disabled piece of UI and even worse it doesn’t look like a native disabled texbox on Vista. I still don’t know about any workarounds and I doubt it if native calls to UxTheme API would solve this.


Submit this story to DotNetKicks Shout it

No comments: