[Lazarus] Setting a groupbox caption bold?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Setting a groupbox caption bold?

Free Pascal - Lazarus mailing list
I have a configuration setting form where I have used group boxes to
collect properties that belong together.
But the groupbox border is not really well defined so I would like to
be able to augment the form visually by setting the caption of the
group boxes to bold.
But I find no such property for the group box...

Is there a way or am I out of luck?

Using Lazarus 2.0.0 with fpc 3.0.4 x64 on Windows 7 x64.
Compiling as 64 bit binaries.


--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a groupbox caption bold?

Free Pascal - Lazarus mailing list
Am 01.04.2019 um 00:09 schrieb Bo Berglund via lazarus:
> I have a configuration setting form where I have used group boxes to
> collect properties that belong together.
> But the groupbox border is not really well defined so I would like to
> be able to augment the form visually by setting the caption of the
> group boxes to bold.
> But I find no such property for the group box...
>
> Is there a way or am I out of luck?

I use this code for TGroupbox, TRadiogroup and TCheckGroup:

procedure BoldGroup(AControl: TWinControl);
var
   i: Integer;
   propinfo: PPropInfo;
   cntrl: TControl;
   fnt: TFont;
begin
   for i:=0 to AControl.ControlCount-1 do begin
     cntrl := AControl.Controls[i];
     propinfo := GetPropInfo(cntrl, 'ParentFont');
     if propinfo <> nil then
       SetOrdProp(cntrl, propinfo, Longint(false));
     propinfo := GetPropInfo(cntrl, 'Font');
     if propinfo <> nil then begin
       fnt := TFont(GetObjectProp(cntrl, 'Font'));
       fnt.Style := [];
       SetObjectProp(cntrl, 'Font', fnt);
     end;
   end;
   AControl.Font.Style := [fsBold];
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a groupbox caption bold?

Free Pascal - Lazarus mailing list
On Mon, 1 Apr 2019 00:42:45 +0200, Werner Pamler via lazarus
<[hidden email]> wrote:

>Am 01.04.2019 um 00:09 schrieb Bo Berglund via lazarus:
>> I have a configuration setting form where I have used group boxes to
>> collect properties that belong together.
>> But the groupbox border is not really well defined so I would like to
>> be able to augment the form visually by setting the caption of the
>> group boxes to bold.
>> But I find no such property for the group box...
>>
>> Is there a way or am I out of luck?
>
>I use this code for TGroupbox, TRadiogroup and TCheckGroup:
>
>procedure BoldGroup(AControl: TWinControl);
>var
>   i: Integer;
>   propinfo: PPropInfo;
>   cntrl: TControl;
>   fnt: TFont;
>begin
>   for i:=0 to AControl.ControlCount-1 do begin
>     cntrl := AControl.Controls[i];
>     propinfo := GetPropInfo(cntrl, 'ParentFont');
>     if propinfo <> nil then
>       SetOrdProp(cntrl, propinfo, Longint(false));
>     propinfo := GetPropInfo(cntrl, 'Font');
>     if propinfo <> nil then begin
>       fnt := TFont(GetObjectProp(cntrl, 'Font'));
>       fnt.Style := [];
>       SetObjectProp(cntrl, 'Font', fnt);
>     end;
>   end;
>   AControl.Font.Style := [fsBold];

I don't really understand what the loop accomplishes...
I don't want to touch the controls inside the group box, just the
group box caption itself...

Could you please show how this would be used for one of my group
boxes? Do I call it inside the form.OnCreate or form.OnShow?

Today I do stuff in OnShow to hide/show group boxes depening on ini
file content so this might be where I'd do this.
Or should it be in OnCreate?


--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a groupbox caption bold?

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On Mon, 1 Apr 2019 00:42:45 +0200, Werner Pamler via lazarus
<[hidden email]> wrote:

>procedure BoldGroup(AControl: TWinControl);
>var
>   i: Integer;
>   propinfo: PPropInfo;
>   cntrl: TControl;
>   fnt: TFont;
>begin
>   for i:=0 to AControl.ControlCount-1 do begin
>     cntrl := AControl.Controls[i];
>     propinfo := GetPropInfo(cntrl, 'ParentFont');
>     if propinfo <> nil then
>       SetOrdProp(cntrl, propinfo, Longint(false));
>     propinfo := GetPropInfo(cntrl, 'Font');
>     if propinfo <> nil then begin
>       fnt := TFont(GetObjectProp(cntrl, 'Font'));
>       fnt.Style := [];
>       SetObjectProp(cntrl, 'Font', fnt);
>     end;
>   end;
>   AControl.Font.Style := [fsBold];

So I tried to put this into Lazarus 2.0.0...
After struggling with illegal whitespace characters when copy pasting
from the news reader into Lazarus I put it into a text editor and
cleaned up these before copy-paste into Lazarus again.

procedure BoldGroup(AControl: TWinControl);
var
        i: Integer;
        propinfo: PPropInfo;
        cntrl: TControl;
        fnt: TFont;
begin
        for i:=0 to AControl.ControlCount-1 do
        begin
                cntrl := AControl.Controls[i];
                propinfo := GetPropInfo(cntrl, 'ParentFont');
                if propinfo <> nil then
                        SetOrdProp(cntrl, propinfo, Longint(false));
                propinfo := GetPropInfo(cntrl, 'Font');
                if propinfo <> nil then
                begin
                        fnt := TFont(GetObjectProp(cntrl, 'Font'));
                        fnt.Style := [];
                        SetObjectProp(cntrl, 'Font', fnt);
                end;
        end;
        AControl.Font.Style := [fsBold];
end;

I also had to add typinfo to uses.

Now it did work but only after rearranging the calls from OnCreate:

This works:
  BoldGroup(gbxValues);
  BoldGroup(gbxDHT);
  BoldGroup(gbxNetwork);
  BoldGroup(gbxAPmode);
  BoldGroup(gbxStationmode);

But this does not work:
  BoldGroup(gbxDHT);
  BoldGroup(gbxNetwork);
  BoldGroup(gbxAPmode);
  BoldGroup(gbxStationmode);
  BoldGroup(gbxValues);

gbxValues is a container groupbox for all of the others.
In the nonworking case the ONLY groupbox that get bold caption is the
gbxValues box...

Seems like the call to bold the caption of the gbxValues container
removes the bold already set on the internal groupboxes...


--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a groupbox caption bold?

Free Pascal - Lazarus mailing list
You did not say that you want to have bold caption for several controls.
In order to "bold" all controls on a form, I use another procedure which
is called from the OnCreate event of a form and recursively iterates
through all controls and their children, seeks for TCustomGroupBox
controls and calls "BoldGroup" for them. Just look at the attachment to
see how it works; the demo contains a hierarchy of various levels of
groupbox containers.

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus

Bold_Groupbox.zip (7K) Download Attachment