How to draw delphi group boxes to have transparent backgrounds
-
03-07-2019 - |
Question
I'm trying to get something very subtle to work, it looks pretty awful right now. I'm trying to paint the background of a TGroupBox which I have overloaded the paint function of so that the corners are show through to their parent object. I've got a bunch of nested group boxes that look very decent without XPThemes.
Is there a way to paint part of a background transparent at runtime. I'm programming the form generator, not using Delphi design view.
Solution
I'm trying to duplicate this problem with the following steps:
1 - Set theme to Windows XP default
2 - Drop a TGroupBox on an empty form (align = alNone)
3 - Drop two TGroupBoxes inside the first one, with align = alBottom and align = alClient
But visually it looks just fine for me.
Can you provide some more info on exactly how you've designed the form? Some code pasted from the .DFM would be fine.
Here's the relevant part of my DFM:
object GroupBox1: TGroupBox
Left = 64
Top = 56
Width = 481
Height = 361
Margins.Left = 10
Caption = 'GroupBox1'
ParentBackground = False
TabOrder = 0
object GroupBox2: TGroupBox
Left = 2
Top = 254
Width = 477
Height = 105
Align = alBottom
Caption = 'GroupBox2'
TabOrder = 0
end
object GroupBox3: TGroupBox
Left = 2
Top = 15
Width = 477
Height = 239
Align = alClient
Caption = 'GroupBox3'
TabOrder = 1
end
end
OTHER TIPS
when i had a situation like that, i worked with TGroupBox initially but then decided to use TPaintBox (called pb in this sample) and simulate the graphical part of the TGroupBox instead.
procedure TfraNewRTMDisplay.pbPaint(Sender: TObject);
const
icMarginPixels=0;
icCornerElipsisDiameterPixels=10;
begin
pb.Canvas.Pen.Color:=clDkGray;
pb.Canvas.Pen.Width:=1;
pb.Canvas.Pen.Style:=psSolid;
pb.Canvas.Brush.Color:=m_iDisplayColor;
pb.Canvas.Brush.Style:=bsSolid;
pb.Canvas.RoundRect(icMarginPixels,
icMarginPixels,
pb.Width-icMarginPixels*2,
pb.Height-icMarginPixels*2,
icCornerElipsisDiameterPixels,
icCornerElipsisDiameterPixels);
end;
Ha, that was lame, I just needed to not set ParentBackground := false
in my constructor and paint the interior of the group box when appropriate.
Ha, that was lame, I just needed to not set ParentBackground := false in my constructor and paint the interior of the group box when appropriate.
maybe there's something i don't know but in my recent experience, it's not as simple as it sounds because of themes & knowing exactly what area to paint. even TCanvas.FloodFill doesn't work reliably for this work probably because at times, the OS doesn't need to repaint everything.