Page 1 of 1

Color background of standard control

Posted: 24 Apr 2019 20:47
by daveplummermd

Can the color background of a standard control, specificlly static text control, be modified?
I am reading the disscussions, many answers that refer to "next versions" that have probably been implemented in my 9.01 CE.

After standard creation here:

Code: Select all

 generatedInitialize() :-          setText("eventDispCtrl"),          This:setSize(231, 13),          This:setState([wsf_ClipSiblings]),          addMouseEnterListener(onMouseEnter),          staticText_ctl := textControl::new(This),          staticText_ctl:setText("Event"),          staticText_ctl:setVerticalScroll(false).
I want to change the background color of "staticText_ctl "

Thak in advance
Dave Plummer

Re: Color background of standard control

Posted: 26 Apr 2019 12:01
by Thomas Linder Puls
Controls are not supposed/designed to change background color.

They are designed to have a background color that fits the dialog. So actually (standard) controls "ask the dialog" to set the background color for them.

A static text control sends the message gui_native::wm_ctlcolorstatic to the dialog and the dialog then returns a brush of the desired kind (e.g. color).

This code will set the background color of a dialog all standard controls to the system "window" color (which is white by default).

Code: Select all

constructors     new : (window Parent). clauses     new(Parent) :-         dialog::new(Parent),         generatedInitialize(),         addNativeMessageHandler(onNative).   facts     windowColor : nativeResponse :=         nativeResult(uncheckedConvert(gui_native::lResult, gui_native::getSysColorBrush(gui_native::color_window))).   predicates     onNative : nativeMessageHandler. clauses     onNative(_Window, Msg, _WParam, LParam) = windowColor :-         gui_api::isCtrlColorMsg(Msg),         This:getVpiWindow() <> LParam,         !.       onNative(_Window, _Msg, _WParam, _LParam) = defaultNativeHandling.
You will have to create a suitable brush (notice that "Sys" brushes does not need to be released, but other brushes must). And you should only return it for your particular control.

Re: Color background of standard control

Posted: 26 Apr 2019 14:25
by daveplummermd
Perfect, thanks!

Re: Color background of standard control

Posted: 26 Apr 2019 15:23
by Gukalov
Hi everybody.
In the similar situation I stupidly used imageControl (instead of staticTextControl)
with the set of image files to change the colors and inscriptions (ImageControl:setImageFile(FileName)).