Take the 2-minute tour ×

I'm writing my Delphi TGraphicControl paint procedure.

I create a canvas and I stretchdraw it onto the graphic area. It works well.

Then I repeat this with another Stretchdraw onto the graphic area but it is drawn in the area of the first Stretchdraw and not onto the graphic area as I direct it.

Is there a way that can place both stretchdraws beside each other in the TGraphicControl's canvas?

share|improve this question
add comment

1 Answer

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:

  r: TRect;
  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);
share|improve this answer
add comment

Your Answer

