Delphi 填充区域会将其从画布上绘制出来
在Delphi 2007中使用以下代码:Delphi 填充区域会将其从画布上绘制出来,delphi,Delphi,在Delphi 2007中使用以下代码: procedure TfrmTest.PaintBox1Paint(Sender: TObject); const Rect_Size = 10; begin PaintBox1.Canvas.Brush.Color := clYellow; PaintBox1.Canvas.FillRect(Rect(0, 0, PaintBox1.width, PaintBox1.height)); PaintBox1.Canvas.Brush.
procedure TfrmTest.PaintBox1Paint(Sender: TObject);
const
Rect_Size = 10;
begin
PaintBox1.Canvas.Brush.Color := clYellow;
PaintBox1.Canvas.FillRect(Rect(0, 0, PaintBox1.width, PaintBox1.height));
PaintBox1.Canvas.Brush.Color := clRed;
DrawARect(PaintBox1.Canvas, 0, 0, Rect_Size, Rect_Size);
end;
procedure TfrmTest.DrawARect(ACanvas: TCanvas; iLeft, iTop, iWidth, iHeight: Integer);
var
rgnMain: HRGN;
begin
rgnMain := CreateRectRgn(iLeft, iTop, iLeft + iWidth, iTop + iHeight);
try
SelectClipRgn(ACanvas.handle, rgnMain);
ACanvas.FillRect(ACanvas.ClipRect);
SelectClipRgn(ACanvas.handle, 0);
finally
DeleteObject(rgnMain);
end;
end;
我明白了:
(黄色区域显示PaintBox1的边界)
(图中显示了一个中间有一个黄色方框[PaintBox1]的表单。但是,我的红色矩形[rgnMain]已在表单的0,0位置绘制)
我的期望是,红色矩形将位于PaintBox1画布的左上角,而不是窗体的画布。为什么不是呢?区域只能与具有Windows句柄的控件一起使用吗
谢谢设备上下文需要窗口句柄。VCL对非窗口控件所做的是通过在TWinControl.PaintControls中使用来偏移为其所在的TWinControl获取的DC的查看端口。新的视图端口以逻辑单元表示。因此,对于不是从TWinControl派生的“TGraphicControl”,可以使用在逻辑坐标上工作的GDI函数。有关详细信息,请参见备注部分,其中说明坐标应以设备单位指定。你可以编辑坐标。我编辑了你的帖子,让图像显示出来。谢谢Sertac,这就解释了