입니다. 귀하의 경우에는 이미지를 그 으십시오. 그러나 그 후에는 양식이 표시되고 드로잉을 덮어 쓰면서 다시 그려집니다. 드로잉을 유지하기 위해 폼을 OnPaint
이벤트로 그릴 수 있습니다.이 이벤트는 폼을 다시 그릴 때마다 호출됩니다.
procedure TForm11.Button1Click(Sender: TObject);
var
Fm: TForm;
begin
Fm := TForm.Create(nil);
try
Fm.Position := poScreenCenter;
Fm.Caption := 'Test';
Fm.Width := 600;
Fm.Height := 400;
Fm.Color := clGreen;
Fm.OnPaint := MyFormPaint;
Fm.ShowModal;
finally
Fm.Free;
end;
end;
procedure TForm11.MyFormPaint(Sender: TObject);
var
Fm: TForm;
R: TRect;
begin
FM := TForm(Sender);
Fm.Canvas.Font.Color := clBlack;
Fm.Canvas.Font.Size := 12;
Fm.Canvas.Pen.Color := clBlack;
Fm.Canvas.Pen.Width := 5;
Fm.Canvas.Brush.Color := clRed;;
Fm.Canvas.Brush.Style := bsSolid;
R.Left := 10;
R.Top := 10;
R.Width := 100;
R.Height := 100;
Fm.Canvas.TextOut(200, 10, 'Hello');
Fm.Canvas.Rectangle(R);
end;
또 다른 해결책은, 비트 맵의 캔버스에 그것을립니다 TImage의의 Picture 속성에 그 비트 맵을 할당하고, 폼에 TImage의를 표시하는 것입니다. 그런 다음 폼을 다시 칠할 필요가있을 때마다 각 컨트롤이 다시 그려지며 이미지는 비트 맵을 다시 그리기 때문에 볼 수 있습니다.
procedure TForm11.Button1Click(Sender: TObject);
var
Fm: TForm;
Img: TImage;
B: TBitmap;
R: TRect;
begin
Fm := TForm.Create(nil);
try
Fm.Position := poScreenCenter;
Fm.Caption := 'Test';
Fm.Width := 600;
Fm.Height := 400;
// Add an image. Make the form the owner. That way, it is automatically
// discarded when you free the form in the `finally` block.
Img := TImage.Create(Fm);
// Make the form the parent too, and make sure the image covers the form.
Img.Parent := Fm;
Img.Align := alClient;
// Get bitmap of the picture. This will automatically create
// a bitmap for it too, which is managed by the image.
// You just have to give it the right dimensions.
B := Img.Picture.Bitmap;
B.Width := Fm.ClientWidth;
B.Height := Fm.ClientHeight;
// The image is not transparent, so you'll have to draw the green background too.
B.Canvas.Brush.Color := clGreen;
B.Canvas.FillRect(B.Canvas.ClipRect);
// Draw on the canvas of the bitmap.
B.Canvas.Font.Color := clBlack;
B.Canvas.Font.Size := 12;
B.Canvas.Pen.Color := clBlack;
B.Canvas.Pen.Width := 5;
B.Canvas.Brush.Color := clRed;;
B.Canvas.Brush.Style := bsSolid;
R.Left := 10;
R.Top := 10;
R.Width := 100;
R.Height := 100;
B.Canvas.TextOut(200, 10, 'Hello');
B.Canvas.Rectangle(R);
Fm.ShowModal;
finally
Fm.Free;
end;
end;
[델파이 7에 캔버스 기능을 사용할 수있게되지 않음 (http://stackoverflow.com/q/7147045/1699210는) – bummi
WM_ERASEBKGRND은 사람 –