我正在编写我的 Delphi TGraphicControl 绘制程序。
我创建了一个画布并将其拉伸到图形区域。它运作良好。
然后我在图形区域上使用另一个 Stretchdraw 重复此操作,但它是在第一个 Stretchdraw 的区域中绘制的,而不是在我引导它时绘制到图形区域上。
有没有一种方法可以在 TGraphicControl 的画布中将两个拉伸绘制并排放置?
TCanvas.StretchDraw
paints a graphic onto a canvas in a given rectangular area. The rectangle should, but does not need to be, within the bounds of the canvas. The owner of the canvas determines those bounds. In your case, it sounds like the canvas owner is the TGraphicControl
object.
If you want two graphics to be painted beside each other, then the TRect
you use to draw the first graphic should represent a rectangle that is adjacent to the TRect
you use for the second graphic. You haven't shown any code yet, so it's hard to tell what's going wrong.
If you use the same TRect
variable for both calls to StretchDraw
, then you need to make sure you modify the rectangle's position between the calls — change the Left
property, for starters.
For example:
var
r: TRect;
begin
r := ClientRect;
// First rectangle takes up left half of control
r.Right := r.Right div 2;
Canvas.StretchDraw(r, graphic1);
// Shift the rectangle to the right half
r.Left := r.Right;
r.Right := ClientRect.Right;
Canvas.StretchDraw(r, graphic2);
end;