我正在尝试使用Canvas绘制类似Dialog的窗体。我可以在其中放置圆角边框和圆角矩形作为标题/标题。我只想用画笔填写标题。Delphi 7 - 如何用画笔填充圆角矩形?
不过,我努力填补这个称号。当使用FillRect
时,所有Form都会重新粉刷。试图在这里搜索,所以如果我错过了,只要指出我去哪里。否则,我该怎么做?使用Delphi 7,OnPaint事件。
procedure TCustomDialog.FormPaint(Sender: TObject);
var
Rect: TRect;
BorderColor: TColor;
BrushColor: TColor;
begin
// Rect for Form's borders;
Rect.Left := 0;
Rect.Top := 0;
Rect.Right := ClientWidth;
Rect.Bottom := ClientHeight;
BorderColor := HtmlToTColor('#ffffff');
BrushColor := HtmlToTColor('#ffffff');
// Here I set the colors of Canvas.Pen (border) and Canvas.Brush (Filling),
// similar to Bootstrap themes/classes (Default, Success, Warning, Danger);
case DialogType of
dtInformation:
begin
BorderColor := HtmlToTColor(Header_Color_Pen_Information);
BrushColor := HtmlToTColor(Header_Color_Brush_Information);
end;
dtSuccess:
begin
BorderColor := HtmlToTColor(Header_Color_Pen_Success);
BrushColor := HtmlToTColor(Header_Color_Brush_Success);
end;
dtWarning:
begin
BorderColor := HtmlToTColor(Header_Color_Pen_Warning);
BrushColor := HtmlToTColor(Header_Color_Brush_Warning);
end;
dtError:
begin
BorderColor := HtmlToTColor(Header_Color_Pen_Error);
BrushColor := HtmlToTColor(Header_Color_Brush_Error);
end;
end;
with Canvas do
begin
Pen.Color := BorderColor;
Pen.Width := Form_Pen_Width;
// Draw rounded borders for Form;
RoundRect(1, 1, Rect.Right - 1, Rect.Bottom - 1, Form_Border_Radius - 1, Form_Border_Radius - 1);
// Rect for Dialog's Header;
Rect.Left := Component_Gutter;
Rect.Top := Component_Gutter;
Rect.Right := ClientWidth - Component_Gutter;
Rect.Bottom := Form_Header_Height;
RoundRect(Component_Gutter, Component_Gutter, ClientWidth - Component_Gutter, Form_Header_Height,
Form_Border_Radius - 2, Form_Border_Radius - 2);
Brush.Color := BrushColor;
FillRect(Rect);
end;
end;
您的图片链接是brok恩。请勿在外部网站上放置图片。 StackOverflow有它自己的图像托管。请直接将您的图片上传到StackOverlow。 –
@RemyLebeau编辑。 –
在绘制圆角矩形的准备工作中,将“Brush”定义为您想要填充的颜色。从doc:*使用RoundRect使用Pen画出一个圆角矩形,并用Brush *填充它。如果我理解你的代码,在'RoundRect()'调用之前移动'Brush.Color:= BrushColor;'行并移除'FillRect()'调用。 –