对角刷风格给我黑色区域 [英] Diagonal brush style gives me black area
问题描述
我想使用此代码绘制一个对角交叉到画布:
InFlateRect(r,-1,-1 );
Canvas.Brush.Color:= clYellow;
Canvas.Brush.Style:= bsFDiagonal;
Canvas.Pen.Color:= clRed;
//Pen.Style:= psClear;
Canvas.Rectangle(r);
但结果是一个黑框。
为什么这个代码的矩形是黑色的?
感谢所有建议
。对于遗漏的信息,我将其扩展:
过程使用TMetaFileCanvas进行绘制。在正常的窗体我可以画任何笔刷样式,像TShape ...
procedure TForm4.FormPaint(Sender:TObject);
var
R:TRect;
begin
R:= ClientRect;
InflateRect(R,-10,-10);
Canvas.Brush.Color:= clYellow;
Canvas.Brush.Style:= bsFDiagonal;
Canvas.Pen.Color:= clRed;
Canvas.Rectangle(R);
end;
产生结果
(不要忘记在表单的
。) OnResize
中无效
请注意,黄线。这确实是 bsFDiagonal
笔刷样式的作用。
从你的问题的措辞(我想画一个对角线交叉[...] ),我怀疑你真的想要别的东西,即在矩形内的一个大十字。这是你不能使用标准的刷子。相反,你必须手动绘制:
procedure TForm4.FormPaint(Sender:TObject);
var
R:TRect;
begin
R:= ClientRect;
InflateRect(R,-10,-10);
Canvas.Brush.Color:= clWhite;
Canvas.Brush.Style:= bsSolid;
Canvas.Pen.Color:= clRed;
Canvas.Rectangle(R);
Canvas.MoveTo(10,10);
Canvas.LineTo(R.Right,R.Bottom);
Canvas.MoveTo(10,R.Bottom);
Canvas.LineTo(R.Right,10);
end;
I want to draw a diagonal cross into a Canvas with this code:
InFlateRect(r, -1, -1);
Canvas.Brush.Color := clYellow;
Canvas.Brush.Style := bsFDiagonal;
Canvas.Pen.Color := clRed;
//Pen.Style := psClear;
Canvas.Rectangle(r);
But the result is a black box.
If I remove the style changing, a normal solid yellow area I got.
Why is the rectangle black with this code?
Thanks for every suggestion
Sorry for missing info, I extend it: This procedure is using TMetaFileCanvas to draw. On normal Form I can draw any brush style, like the TShape...
procedure TForm4.FormPaint(Sender: TObject);
var
R: TRect;
begin
R := ClientRect;
InflateRect(R, -10, -10);
Canvas.Brush.Color := clYellow;
Canvas.Brush.Style := bsFDiagonal;
Canvas.Pen.Color := clRed;
Canvas.Rectangle(R);
end;
produces the result
(Don't forget to Invalidate
in the form's OnResize
.)
Notice that the area is filled with diagonal yellow lines. This is indeed what the bsFDiagonal
brush style does.
From the wording of your question ("I want to draw a diagonal cross [...]"), I suspect you actually want something else, namely, a big cross inside the rectangle. This you cannot achieve using the standard brushes at all. Rather, you have to draw it manually:
procedure TForm4.FormPaint(Sender: TObject);
var
R: TRect;
begin
R := ClientRect;
InflateRect(R, -10, -10);
Canvas.Brush.Color := clWhite;
Canvas.Brush.Style := bsSolid;
Canvas.Pen.Color := clRed;
Canvas.Rectangle(R);
Canvas.MoveTo(10, 10);
Canvas.LineTo(R.Right, R.Bottom);
Canvas.MoveTo(10, R.Bottom);
Canvas.LineTo(R.Right, 10);
end;
这篇关于对角刷风格给我黑色区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!