delphi - How to color the background of a TComboBox with VCL styles enabled -
i trying color background of tcombobox vcl styles enabled way described in article not working.
depending of delphi version must
delphi xe2
for delphi xe2 must write style hook
uses vcl.styles, vcl.themes; type tcomboboxstylehookext= class(tcomboboxstylehook) procedure updatecolors; strict protected procedure wndproc(var message: tmessage); override; public constructor create(acontrol: twincontrol); override; end; twincontrolclass= class(twincontrol); { tcomboboxstylehookext } constructor tcomboboxstylehookext.create(acontrol: twincontrol); begin inherited; updatecolors; end; procedure tcomboboxstylehookext.updatecolors; const colorstates: array[boolean] of tstylecolor = (sccomboboxdisabled, sccombobox); fontcolorstates: array[boolean] of tstylefont = (sfcomboboxitemdisabled, sfcomboboxitemnormal); var lstyle: tcustomstyleservices; begin if control.enabled }//use control colors begin brush.color := twincontrolclass(control).color; fontcolor := twincontrolclass(control).font.color; end else begin //if not enabled. use current style colors lstyle := styleservices; brush.color := lstyle.getstylecolor(colorstates[control.enabled]); fontcolor := lstyle.getstylefontcolor(fontcolorstates[control.enabled]); end; end; procedure tcomboboxstylehookext.wndproc(var message: tmessage); begin case message.msg of wm_ctlcolormsgbox..wm_ctlcolorstatic, cn_ctlcolormsgbox..cn_ctlcolorstatic: begin updatecolors; settextcolor(message.wparam, colortorgb(fontcolor)); setbkcolor(message.wparam, colortorgb(brush.color)); message.result := lresult(brush.handle); handled := true; end; cm_enabledchanged: begin updatecolors; handled := false; end else inherited wndproc(message); end; end; initialization tstylemanager.engine.registerstylehook(tcombobox, tcomboboxstylehookext); delphi xe3/xe4
simply remove seclient value styleelements propertty
combobox1.styleelements:=[sefont, seborder]; combobox2.styleelements:=[sefont, seborder]; combobox3.styleelements:=[sefont, seborder]; 
Comments
Post a Comment