That's because you're calling Refresh
method. This method immediately forces the control to repaint. Draw your painting in the OnPaint
event method instead and call just that Refresh
or Invalidate
on that shape object to force it to trigger the OnPaint
event:
procedure TController.DrawGrind;
begin
ShowMessage('I try do draw something');
// if you use Refresh instead of Invalidate, the control will be forced
// to repaint itself immediately
FView.Shape1.Invalidate;
end;
procedure TForm1.Shape1Paint(Sender: TObject);
begin
Shape1.Canvas.Pen.Width := 5;
Shape1.Canvas.Pen.Color := clRed;
Shape1.Canvas.Pen.Style := psSolid;
Shape1.Canvas.MoveTo(0, 0);
Shape1.Canvas.LineTo(Shape1.ClientWidth, Shape1.ClientHeight);
end;
In your original code you were also trying to draw on quite weird position. Canvas coordinates starts at [0; 0]
and goes to [Control.ClientWidth; Control.ClientHeight]
.