gpt4 book ai didi

delphi - 组件组件叠加的透明度

转载 作者:行者123 更新时间:2023-12-02 10:58:37 26 4
gpt4 key购买 nike

首先,如果需要更多信息,请询问我是否愿意添加更多信息。 (明天 09:00 GMT+1 之前无法提前回复)

在delphi中使用圆形组合框和圆形按钮(TCustomControls)开发应用程序出现的问题主要是组件之间以某种方式分层的问题正如图一(下图)所示

当组件绘制在彼此的顶部时,表单的背景仍然在角落处发光。

对于每个自定义控件,我都会自己绘制组件。但我似乎无法掌握如何让它正常工作。

我尝试过以下方法

 - Params.exStyle := Params.exStyle + WS_EX_TRANSPARENT; 
- ScanLine and set the pixels equal to the background (which doesn't work as one
would suspect)
- WSEraseBackground procedure empty

但似乎没有什么可以解决我的问题(WS_EX_TRANSPARENT 确实解决了,但是当单击组件时,它似乎翻转了 Z 顺序)

我重写绘画事件并只绘制圆角矩形(在我看来不应该是一个大的)

Current Issue

How I would like to see it work

procedure TRoundedComboBox.Paint;
var
Rect : TRect;

procedure DrawFirst();
begin
{first}
Canvas.Pen.Color := FColorArray[0];
Canvas.Brush.Color := FColorArray[0];
Canvas.RoundRect(0,
0,
width,
FDefaultComboBoxHeight,
20,
20);
end;


procedure DrawFirstInner();
begin
{first inner}
Canvas.Pen.Color := FColorArray[1];
Canvas.Brush.Color := FColorArray[1];
Canvas.RoundRect(0,
1,
width,
FDefaultComboBoxHeight,
20,
20);
end;


procedure DrawSecondInner();
begin
{second inner}
Canvas.Pen.Color := FColorArray[2];
Canvas.Brush.Color := FColorArray[2] ;
Canvas.RoundRect(0,
round(FDefaultComboBoxHeight /2),
width,
FDefaultComboBoxHeight,
20,
20);
end;


procedure DrawText();
begin
{Text}
Canvas.Font := FFont;
Canvas.Font.Color := FColorArray[3];
Canvas.Brush.Style := bsClear;
FTextRect := TRect.Create(4, 0, width -20, FDefaultComboBoxHeight);
Canvas.TextRect(FTextRect,
12,
round(FTextRect.Height /2) - round(Canvas.TextExtent(FText).Height /2),
FText);
end;


procedure DrawTriangle();
begin
{Triangle}
Canvas.MoveTo(FPoints[0].x, FPoints[0].y);
Canvas.Pen.Color := FColorArray[4];
Canvas.Brush.Color := FColorArray[4];
Canvas.Polygon(FPoints);
end;

begin
//inherited;

FListBox.Invalidate;
FListBox.Visible := FEnabledBtnDown;

if (FEnabledBtnDown) then
begin
FlistBOx.SetFocus;
end;


Height := IfThen (FEnabledBtnDown, FMaxmimumComboBoxHeight, FDefaultComboBoxHeight);

DrawFirst;

DrawFirstInner;

DrawSecondInner;

DrawTriangle;

DrawText;
end;

最佳答案

您可以从 TCustomTransparentControl(单元 Controls.pas)派生。如果这不是一个选项,请查看 TCustomTransparentControl 的工作原理。

关于delphi - 组件组件叠加的透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26999171/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com