Draw a thematic border TEdit

I want to draw a TEdit theme border in Paintbox. The code should work under Windows Vista and 7. I tried the following. It works only under Windows XP.

var
  Details: TThemedElementDetails;   //uses Themes
begin
  if ThemeServices.ThemesEnabled then
  begin
    Details := ThemeServices.GetElementDetails(teEditRoot);
    ThemeServices.DrawElement(PaintBox1.Canvas.Handle, Details, PaintBox1.ClientRect);
  end;
end;

In Windows XP, everything is fine. But under Windows Vista and 7, the border is dark gray. All 4 sides are the same color. But TEdit for Vista looks different: the upper border is dark gray. The right border is medium gray. The left and bottom borders are light gray. Hope you understand the difference. How to draw it right? Thank!

+5
source share
1 answer

Try:

R := Rect(15, 15, 80, 30);
DrawThemeBackground(ThemeServices.Theme[teEdit], PaintBox1.Canvas.Handle, EP_EDITBORDER_NOSCROLL, ETS_NORMAL, R, @R);
/// DrawThemeBackground(ThemeServices.Theme[teEdit], PaintBox1.Canvas.Handle, EP_EDITTEXT, ETS_NORMAL, R, @R); <<< XP Behaviour

If you want your code to run in XP, you have to do it conditionally, since on WinXP you have to use the second one.

+5
source

All Articles