Delphi屏幕绘图

以下代码在全屏幕中心绘制一个十字架:

procedure TForm1.Button1Click(Sender: TObject);
var
   FullscreenCanvas:TCanvas;
    DC:HDC;
begin
    DC:=GetDC(0);//取得屏幕的DC,参数0指的是屏幕
     FullscreenCanvas := TCanvas.Create;//创建一个CANVAS对象
     FullscreenCanvas.Handle := DC;   //将画布关联到屏幕句柄,以便能做图
    FullscreenCanvas.MoveTo(screen.Width div 2,0);
     FullscreenCanvas.LineTo(screen.Width div 2,768);
     FullscreenCanvas.MoveTo(0,Screen.Height div 2);
    FullscreenCanvas.LineTo(1024,Screen.Height div 2);
end;

//以下代码实现定时在屏幕正中绘一个十字,一个正方形,一个圆形

procedure TForm1.Timer1Timer(Sender: TObject);
var
MyCanvas:TCanvas;
DC:HDC;
begin
DC:=GetDC(0);
MyCanvas:=TCanvas.Create;
//MyCanvas.Brush.Color:=clblack; //黑色填充色
MyCanvas.Brush.Style:=bsClear; //无背景色
MyCanvas.Handle:=DC;
//MyCanvas.Brush.Bitmap:=image1.Picture.Bitmap;
MyCanvas.MoveTo(screen.Width div 2,0);
MyCanvas.LineTo(screen.Width div 2,Screen.Height);
MyCanvas.MoveTo(0,screen.Height div 2);
MyCanvas.LineTo(screen.Width,screen.Height div 2);
MyCanvas.Rectangle(Screen.Width div 2-100,Screen.Height div 2-100,Screen.Width div 2+100,Screen.Height div 2+100); //屏幕正中心绘制一个正方形
MyCanvas.Ellipse(Screen.Width div 2-100,Screen.Height div 2-100,Screen.Width div 2+100,Screen.Height div 2+100);   //屏幕正中心绘制一个圆形
MyCanvas.TextOut(720,300,'我测试再测试,测试直接在屏幕上写字的感觉!'); //在Canvas对象上添加文字
end;

你可能感兴趣的:(DELPHI,&,PASCAL)