如何绘制delphi组框具有透明背景

发布于 2024-07-05 17:36:26 字数 203 浏览 7 评论 0原文

我正在尝试让一些非常微妙的东西发挥作用,现在看起来非常糟糕。 我正在尝试绘制 TGroupBox 的背景,我已重载了该 TGroupBox 的绘制函数,以便角落显示到其父对象。 我有一堆嵌套的组框,在没有 XPThemes 的情况下看起来非常不错。

有没有办法在运行时将背景的一部分绘制为透明。 我正在对表单生成器进行编程,而不是使用 Delphi 设计视图。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小瓶盖 2024-07-12 17:36:26

当我遇到这样的情况时,我最初使用 TGroupBox,但后来决定使用 TPaintBox(在本示例中称为 pb)并模拟 TGroupBox 的图形部分。

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;

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;
九厘米的零° 2024-07-12 17:36:26

哈,那太蹩脚了,我只需要在构造函数中不设置 ParentBackground := false 并在适当的时候绘制组框的内部。

也许有一些我不知道的事情,但根据我最近的经验,由于主题和内容,它并不像听起来那么简单。 确切地知道要绘制的区域。 即使 TCanvas.FloodFill 也不能可靠地完成这项工作,可能是因为有时操作系统不需要重新绘制所有内容。

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.

巷子口的你 2024-07-12 17:36:26

哈,那太蹩脚了,我只需要在构造函数中不设置ParentBackground := false,并在适当的时候绘制组框的内部即可。

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.

扬花落满肩 2024-07-12 17:36:26

我尝试通过以下步骤重复此问题:

1 - 将主题设置为 Windows XP 默认值

2 - 在空表单上放置一个 TGroupBox (align = alNone)

3 - 将两个 TGroupBox 放入第一个 TGroupBox 中,对齐 = alBottom 和align = alClient

但在视觉上它看起来对我来说很好。

您能否提供更多有关您如何设计表单的信息? 从 .DFM 粘贴一些代码就可以了。

这是我的 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文