具有自定义风格的Delphi项目

发布于 2025-02-09 16:17:01 字数 284 浏览 1 评论 0原文

我想创建一个具有自定义样式的Delphi项目,例如下面的图像。

如您所见,主体是透明的,其中有一些组件。

如何创建这个透明的主角?

PS:我想创建VCL项目,然后由Photoshop绘制了此图像。

I want to create a Delphi project with a custom Style, like the below image.

image

As you can see, the MainForm is transparent, and there are some components inside of it.

How can I create this transparent MainForm?

P.S:I want to create VCL project and i drawn this image by Photoshop.

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

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

发布评论

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

评论(1

谎言 2025-02-16 16:17:01

假设您使用的是FireMonKey,因为您没有指定VCL或FMX。

您实际上不需要为此创建一种样式。更简单的方法是:

  1. 将表单透明属性设置为true
  2. trectangle放在表单上,​​并使其与最左右和将颜色等调整为您的喜好。
  3. 将另一个trectangle放在您的表单上,并将对齐设置为client。然后,您可以调整不透明度透明度的属性,fill color> color的属性,然后stroke> stroke << 代码>边框。
  4. 我看到照片中左右之间有一个小空间。这可以通过在第二个trectangle上设置保证金左值来完成。

现在,这应该看起来像您希望提供的东西,您可以禁用表单的边界。我们还需要做1件事,以避免将控件显示为透明。我们需要在表单上放置一个布局。不是矩形。如果将控件放置在矩形上,则控件也将是透明的。如果您希望控件具有相同的透明值,则将其放在矩形上。否则请执行以下操作:

  1. tlayout放在表单上。不是矩形。
  2. 将对齐属性设置为内容。这将使它重叠。
  3. 将布局的<代码>左属性设置为您放置的左矩形宽度 +您放置的客户矩形的边距值,以补偿小空间。
  4. 将您的控件放在布局上,它们应以默认不透明度显示。

要做的最后一件事是实现窗口拖动。假设您禁用了边框,则您的用户将无法移动窗口,因为没有边框可以拖动。在组件的Mousedown事件中,您希望拖动启动添加以下代码:

procedure TForm1.rctngl1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
begin
  StartWindowDrag;
end;

现在应该完成。

编辑:发布此答案后,我举了一个示例:

Assuming you're using Firemonkey since you dont specify VCL or FMX.

You don't really need to create a style for this. Rather a simpler way would be to:

  1. Set the form transparent property to True
  2. Place a TRectangle on the form and make it align to Most left and adjust the color etc to your liking.
  3. Place another TRectangle on your form and set the alignment to Client. You can then adjust the Opacity property for transparency, the fill property for color and then the stroke for the border.
  4. I see a small space between the left and right in the photo. This can be done by setting a margin left value on the second TRectangle you placed.

Now this should look like you what want it to be provided you disabled the border of the form. There is 1 more thing we need to do to avoid having the controls show as transparent. We need to place a layout on the form. Not the rectangle. If you place the controls on the rectangle with opacity the controls will also be transparent. If you want the controls to have the same transparency value place it on the rectangle. Otherwise do the following:

  1. Place a TLayout on the form. Not the rectangle.
  2. Set the align property to Contents. This will make it overlap everything.
  3. Set the margin left property of the layout to the width of the left rectangle you placed + the margin value of the client rectangle you placed to compensate for the little space.
  4. Place your controls on the layout and they should show with default opacity.

One last thing to do is implement window drag. Assuming you disabled the border, your users will not be able to move the window at all since there is no border to drag. On the MouseDown event of the component you want the drag to start add the following code:

procedure TForm1.rctngl1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
begin
  StartWindowDrag;
end;

You should be all done now.

EDIT: I made an example after posting this answer: FMX Semi Transparent Form

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