Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw themed border of a TEdit

Tags:

delphi

I want to draw the themed border of a TEdit in a Paintbox. The code must be functional under Windows Vista and 7. I have 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;

Under Windows XP all ist OK. But under Windows Vista and 7 the border is painted in dark gray. All 4 sides in the same color. But a TEdit under Vista looks different: The top border has a dark gray. The right border a medium gray. The left and bottom borders have a light gray. I hope you understand the difference. How to paint it in the right way? Thanks!

like image 899
TomCat500 Avatar asked Aug 13 '10 12:08

TomCat500


1 Answers

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 should make that conditional, as on WinXP you should use the 2nd one.

like image 113
Trinidad Avatar answered Oct 18 '22 02:10

Trinidad