Thursday, 15 March 2012

delphi - Out-of-the-box flat borderless button -



delphi - Out-of-the-box flat borderless button -

i'm looking out-of-the-box way of configuring flat borderless button. can add together button palette , configure in design-time, without runtime overrides. i can utilize devexpress components, avoid lookandfeel overrides or creating custom theme that.

the problem controls allow edit properties, miss others.

here's have tried:

component tabstop focusrect text v.align borderless color ---------------------------------------------------------------------------- tbutton v v v - - tspeedbutton v v v - - tlabel - - v v v tpanel v - v v v tstatictext v - - v v tcxbutton v v v - v tcxlabel - - v v v ---------------------------------------------------------------------------- * text v.align - vertical text alignment center * borderless - no borders in default/unfocused state ** color - ability set face color

another approach override tbutton class via ownerdraw magic , set unit first every forms' uses clause?

do know of alternatives allow create/configure such flat button in designtime having standard delphi 7 , basic devexpress components?

edit: address downvoters, presumably think bad question because asks how existing tools without reinventing bicycle.

this not garage project. there half dozen developers , build-machines, meaning installing updated component containing custom button each time each 1 of them noticeable problem overall. the question not looking 3rd party component. i'm asking if there's known way configure existing controls suit need. don't create new command each time need hotlink label right?

p.s. target os windows xp , up

below interposer class illustration modifies tbutton of bs_ownerdraw style. noted, can set unit used after 'stdctrls'.

type tbutton = class(stdctrls.tbutton) protected procedure setbuttonstyle(adefault: boolean); override; procedure cnctlcolorbtn(var message: tmessage); message cn_ctlcolorbtn; procedure cndrawitem(var message: twmdrawitem); message cn_drawitem; procedure wmpaint(var message: twmpaint); message wm_paint; end; ... procedure tbutton.setbuttonstyle(adefault: boolean); begin if handleallocated perform(bm_setstyle, bs_ownerdraw, 1); end; procedure tbutton.cnctlcolorbtn(var message: tmessage); begin dword(message.result) := createsolidbrush($79ff); end; procedure tbutton.cndrawitem(var message: twmdrawitem); var dc: hdc; saveobj: hgdiobj; r: trect; begin r := clientrect; dc := message.drawitemstruct.hdc; saveobj := selectobject(dc, font.handle); setbkmode(dc, transparent); drawtext(dc, pchar(caption), -1, r, dt_singleline or dt_center or dt_vcenter); selectobject(dc, saveobj); message.result := 1; end; procedure tbutton.wmpaint(var message: twmpaint); var dc: hdc; r: trect; begin inherited; if getfocus = handle begin dc := getdc(handle); selectobject(dc, getstockobject(dc_brush)); setdcbrushcolor(dc, $ff); r := clientrect; inflaterect(r, -2, -2); framerect(dc, r, dc_brush); releasedc(handle, dc); end; end;

looks on w7 this:

delphi button devexpress delphi-7 vcl

No comments:

Post a Comment