views:

1905

answers:

4

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.

+1  A: 

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
JosephStyons
Thanks for the response, I guess I have to clarify my question, I'm not drawing them in design mode, these are being created at runtime as designed by a user of our application. So there's no DFM and not necessarily any ability to align these group boxes since they're positioned absolutely.
Peter Turner
Ahh, I see. That makes a difference. These look promising; I'm still poking around trying to figure this out. http://www.torry.net/pages.php?id=152
JosephStyons
Thanks, I tried the transparent box and that led me to try to canvas.copyrect the parent tgroupbox, which led me to the eventual obvious answer which was defaulted in your DFM.
Peter Turner
I'm really glad you figured it out. I feel a little guilty over getting "Answered" status for this one; at best I just gave a pointer to some useful information, and you figured it out. Congrats....
JosephStyons
+2  A: 

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;
X-Ray
+1  A: 

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.

Peter Turner
+1  A: 

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.

X-Ray