Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2019-04

Setting a groupbox caption bold?

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

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

Reply by email

Werner Pamler
to Bo Berglund
Bo Berglund wrote 8 lines
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];

Reply by email

Bo Berglund
to Werner Pamler
Werner Pamler wrote 32 lines
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

Reply by email

Bo Berglund
to Werner Pamler: I use this code for TGroupbox, TRadiogroup and TCheckGroup: procedure BoldGroup(AControl:…
Werner Pamler wrote 20 lines
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

Reply by email

Werner Pamler
to Bo Berglund

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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Bold_Groupbox.zip
Type: application/x-zip-compressed
Size: 5742 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20190401/50a1d58b/attachment-0001.bin>

Reply by email