在德爾福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.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的邊界)。
alt text http://www.freeimagehosting.net/uploads/62cf687d29.jpg
(圖像顯示在中心一個黃色的盒子[PaintBox1]一種形式。但是我的紅rectange [rgnMain]已在pos 0,0表格上繪製)
我的期望是紅色矩形將位於PaintBox1畫布的左上角,而不是窗體的畫布。爲什麼不是?區域只能用於具有Windows句柄的控件嗎?
謝謝
我編輯了你的文章,使圖像顯示出來。 – 2010-06-10 02:56:40
謝謝你,梅森 – Xanyx 2010-06-10 05:17:23