Delphi: TPanel and text indent -


enter image description here how can make view in yellow rectangle. using tpanel + color? if yes indent of text left?

thanks , advices!

the simplest way use tpanel. set parentbackground false, bevelouter bvnone, font.color clwhite, font.style [fsbold] , color background colour want. put 1 or 2 spaces in front of text in caption property, ' ordinary tpanel.'.

screenshot http://privat.rejbrand.se/tpanelspaceprefix.png

a more elegant soution write custom control. easy. example:

unit captionbar;  interface  uses   windows, sysutils, classes, controls, graphics;  type   tcaptionbar = class(tcustomcontrol)   private     fcolor: tcolor;     fcaption: tcaption;     fellipsis: boolean;     findent: integer;     procedure setcaption(const value: tcaption);     procedure setcolor(const value: tcolor);     procedure setellipsis(const value: boolean);     procedure setindent(const value: integer);   protected     procedure paint; override;   public     constructor create(aowner: tcomponent); override;   published     property font;     property anchors;     property align;     property caption: tcaption read fcaption write setcaption;     property color: tcolor read fcolor write setcolor default clskyblue;     property ellipsis: boolean read fellipsis write setellipsis default true;     property indent: integer read findent write setindent default 4;   end;  procedure register;  implementation  procedure register; begin   registercomponents('rejbrand 2009', [tcaptionbar]); end;  { tcaptionbar }  constructor tcaptionbar.create(aowner: tcomponent); begin   inherited;   findent := 4;   fcolor := clskyblue;   fellipsis := true; end;  procedure tcaptionbar.paint; const   ellipsis: array[boolean] of cardinal = (0, dt_end_ellipsis); var   r: trect; begin   inherited;   canvas.brush.color := fcolor;   canvas.fillrect(clientrect);   r := clientrect;   r.left := r.left + findent;   canvas.font.assign(font);   drawtext(canvas.handle,     pchar(fcaption),     length(fcaption),     r,     dt_singleline or dt_left or dt_vcenter or ellipsis[fellipsis]); end;  procedure tcaptionbar.setcaption(const value: tcaption); begin   if not samestr(fcaption, value)   begin     fcaption := value;     invalidate;   end; end;  procedure tcaptionbar.setcolor(const value: tcolor); begin   if fcolor <> value   begin     fcolor := value;     invalidate;   end; end;  procedure tcaptionbar.setellipsis(const value: boolean); begin   if fellipsis <> value   begin     fellipsis := value;     invalidate;   end; end;  procedure tcaptionbar.setindent(const value: integer); begin   if findent <> value   begin     findent := value;     invalidate;   end; end;  end. 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -