Ple*_*rds 10 delphi user-interface frame delphi-2006
我想制作一个基于TFramewith TLMDShapeControl(用于绘制圆角背景)和TEdit控件(也可以是a TComboBox或a TDBEdit等)的组件.之后,我将使用"添加到调色板"命令将其转换为可重用的组件控件.
问题在于我需要宽度灵活,因此我有想法将所有内容都转动到Frame内部alClient并TEdit使用5像素边距,这样用户就可以看到圆角.
这太糟糕了,因为我无法使用Align并将组件设置在另一个的顶部.现在我每次必须使用它时都要复制和粘贴组件!: - (((
我看到正确的事情的唯一方法是只使用TEditwith alClient和5px边距而不是TShape.相反,我可以使TFrame透明度为圆角,因此不会看起来不同颜色或丑陋TImages.
但是我该怎么做?
有没有人有任何代码示例?

TLa*_*ama 14
要回答你的问题如何使用圆角制作框架你可以尝试这样的东西,但你会对结果不满意,因为CreateRoundRectRgn这里使用的没有抗锯齿.
type
TFrame1 = class(TFrame)
Edit1: TEdit;
Button1: TButton;
protected
procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
end;
implementation
procedure TFrame1.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
var
Region: HRGN;
begin
inherited;
Region := CreateRoundRectRgn(0, 0, ClientWidth, ClientHeight, 30, 30);
SetWindowRgn(Handle, Region, True);
end;
Run Code Online (Sandbox Code Playgroud)
更新:
由于GDI没有任何支持电弧渲染的抗锯齿的功能,我在这里发布了一个圆形矩形形状(只是一个纯填充的圆形矩形)的例子,它使用GDI +(为此你需要GDI +包装器from here).
以下属性对其使用很重要:
unit RoundShape;
interface
uses
SysUtils, Classes, Controls, Graphics, GdiPlus;
type
TCustomRoundShape = class(TGraphicControl)
private
FRadius: Integer;
FAlphaValue: Integer;
procedure SetRadius(Value: Integer);
procedure SetAlphaValue(Value: Integer);
protected
procedure Paint; override;
property Radius: Integer read FRadius write SetRadius default 10;
property AlphaValue: Integer read FAlphaValue write SetAlphaValue default 255;
public
constructor Create(AOwner: TComponent); override;
end;
TRoundShape = class(TCustomRoundShape)
public
property Canvas;
published
property Align;
property AlphaValue;
property Anchors;
property Color;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property Radius;
property ShowHint;
property Visible;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnMouseActivate;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
end;
procedure Register;
implementation
{ TCustomRoundShape }
constructor TCustomRoundShape.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 213;
Height := 104;
FRadius := 10;
FAlphaValue := 255;
end;
procedure TCustomRoundShape.SetRadius(Value: Integer);
begin
if FRadius <> Value then
begin
FRadius := Value;
Invalidate;
end;
end;
procedure TCustomRoundShape.SetAlphaValue(Value: Integer);
begin
if FAlphaValue <> Value then
begin
FAlphaValue := Value;
Invalidate;
end;
end;
procedure TCustomRoundShape.Paint;
var
GPPen: TGPPen;
GPColor: TGPColor;
GPGraphics: IGPGraphics;
GPSolidBrush: IGPSolidBrush;
GPGraphicsPath: IGPGraphicsPath;
begin
GPGraphicsPath := TGPGraphicsPath.Create;
GPGraphicsPath.Reset;
GPGraphicsPath.AddArc(0, 0, FRadius, FRadius, 180, 90);
GPGraphicsPath.AddArc(ClientWidth - FRadius - 1, 0, FRadius, FRadius, 270, 90);
GPGraphicsPath.AddArc(ClientWidth - FRadius - 1, ClientHeight - FRadius - 1,
FRadius, FRadius, 0, 90);
GPGraphicsPath.AddArc(0, ClientHeight - FRadius - 1, FRadius, FRadius, 90, 90);
GPGraphicsPath.CloseFigure;
GPColor.InitializeFromColorRef(ColorToRGB(Color));
GPColor.Alpha := FAlphaValue;
GPPen := TGPPen.Create(GPColor);
GPSolidBrush := TGPSolidBrush.Create(GPColor);
GPGraphics := TGPGraphics.Create(Canvas.Handle);
GPGraphics.SmoothingMode := SmoothingModeAntiAlias;
GPGraphics.FillPath(GPSolidBrush, GPGraphicsPath);
GPGraphics.DrawPath(GPPen, GPGraphicsPath);
end;
procedure Register;
begin
RegisterComponents('Stack Overflow', [TRoundShape]);
end;
end.
Run Code Online (Sandbox Code Playgroud)
结果(应用SmoothingModeAntiAlias平滑模式):

可以说使用GDI +进行如此微小的事情是一个很大的开销,但纯粹的GDI渲染没有抗锯齿,结果看起来很难看.以下是使用纯GDI渲染的相同圆角矩形的示例:

| 归档时间: |
|
| 查看次数: |
3902 次 |
| 最近记录: |