扫一扫
分享文章到微信

扫一扫
关注官方公众号
至顶头条
表 1--1
Canvas方法	CDC方法	功能
Arc		Arc		画一个椭圆弧
Chord		Chord		画一根玄。
CopyRect			拷贝指定矩形区域中图象到指定矩形
Draw		BitBlt		拷贝位图
Ellipse		Ellipse		画椭圆
FillRect	PaintRgn	使用刷子填充一个又一个矩型
FloodFill	FloodFill	用当前刷子填充区域
FrameRect	FrameRect	画一个矩形框
Lineto		Lineto		画线到
Moveto		Moveto		移	到
Pie		Pie		画扇形
Polygon		Polygon		画多边形
PolyLine	PolyLine	画多根相连的线
Rectangle	Rectangle	画一个实心矩形
RoundRect	RoundRect	画一个圆角的矩形
StretchDraw	StretchBlt	从源图象中
				移动图象到指定矩形
TextWidth	GetCharWidth	返回字符宽
TextOut		TextOut		在指定坐标写字
TextRect	ExtTextOut	在制定矩形中写字
procedureTSDIAppForm.FormPaint(Sender:TObject);
begin
canvas.FillRect(rect);{清空桌面画布}
withSDIappformdo
posx:=clientwidthdiv2;
posy:=clientheightdiv2;{确定客户区中心点}
casedetectIof
1:
begin
setpenstate;
canvas.Ellipse(posx-50,posy-50,posx+50,posy+50);
//penwidth:=oldwidth;
end;{在客户区中心点画圆}
2:
begin
setpenstate;
canvas.MoveTo(posx-60,posy-60);
canvas.LineTo(posx+60,posy+60);
//penwidth:=oldwidth;
end;{在客户区画直线}
3:
begin
fposx:=trunc(50*cos(pi/6));
fposy:=trunc(50*sin(pi/6));
setpenstate;
Canvas.Polygon([Point(posx-fposy,posy-fposx),
Point(posx+fposy,posy-fposx),
Point(posx+50,posy),Point(posx+fposy,posy+fposx),
point(posx-fposy,posy+fposx),point(posx-50,posy)]);
//penwidth:=oldwidth;
end;{在客户区中心点画多边形}
4:
begin
setpenstate;
canvas.RoundRect(posx-100,posy-50,posx+100,posy+50,
20,20);
end;{在客户区中心点画带圆角的矩形}
5:
begin
setpenstate;
sdiappform.Canvas.Brush.Color:=clred;
canvas.Rectangle(posx-100,posy-50,posx+100,posy+50);
sdiappform.Canvas.Brush.Color:=bcolor;
end{在客户区中心点用红色刷子画矩形}
else
begin
canvas.Font:=formfont;
canvas.TextOut(30,posy,str);
end;
end;{写字}
end;
上面程序中出现的变量在事件OnCreate中初始化。
procedureTSDIAppForm.FormCreate(Sender:TObject);
begin
str:=;{要写在画布上的字符串}
formfont:=canvas.font;{字体和大小}
detectI:=0;{确定画布上出现何种图形的参数}
rect:=sdiappform.ClientRect;{客户区矩形}
oldwidth:=sdiappform.Canvas.Pen.Width;{最初画笔宽度}
penwidth:=oldwidth;{画笔宽度}
penstyle:=sdiappform.Canvas.Pen.Style;{画笔类型}
pencolor:=sdiappform.Canvas.Pen.Color;{画笔颜色}
bcolor:=sdiappform.Canvas.Brush.Color;{画刷颜色}
end;
procedureTSDIAppForm.setpenstate;
begin
withsdiappform.Canvas.Pendo
begin
color:=pencolor;
style:=penstyle;
width:=penwidth;
end;
end;
procedureTSDIAppForm.LineColor1Click(Sender:TObject);
begin
ifcolordialog1.Executethen
begin
pencolor:=colordialog1.Color;
SdiAppForm.Canvas.Pen.Style:=psInsideFrame;
ifpenwidth$#@60;1then
SdiAppForm.Canvas.Pen.Width:=3;
SdiAppForm.Canvas.Pen.Color:=pencolor;
invalidate;
end;
end;{完成画笔颜色设定}
//{完成画笔笔形设定}
procedureTSDIAppForm.Solid1Click(Sender:TObject);
begin
penStyle:=pssolid;
invalidate;
end;
procedureTSDIAppForm.Dot1Click(Sender:TObject);
begin
PenStyle:=psdot;
invalidate;
end;
procedureTSDIAppForm.Dash1Click(Sender:TObject);
begin
penStyle:=psdash;
invalidate;
end;
procedureTSDIAppForm.DashDot1Click(Sender:TObject);
begin
PenStyle:=psdashdot;
invalidate;
end;
procedureTSDIAppForm.DashDotDot1Click(Sender:TObject);
begin
penStyle:=psdashdotdot;
invalidate;
end;
//////////////////////////////////
procedureTSDIAppForm.RoundRect1Click(Sender:TObject);
begin
detectI:=4;
invalidate;
end;
procedureTSDIAppForm.Rectangle1Click(Sender:TObject);
begin
detectI:=5;
invalidate;
end;
procedureTSDIAppForm.Helloworld1Click(Sender:TObject);
begin
detectI:=0;
str:=helloworld!!;
Invalidate;
end;
procedureTSDIAppForm.Imateacher1Click(Sender:TObject);
begin
detectI:=0;
str:=Iamateacher!!;
Invalidate;
end;
procedureTSDIAppForm.Fonts1Click(Sender:TObject);
begin
iffontdialog1.Executethen
begin
detectI:=0;
formfont:=fontdialog1.font;
invalidate;
end;
end;{设定字体和大小}
//拷贝图形到剪贴板
procedureTSDIAppForm.EditCopy1Execute(Sender:TObject);
var
bmp:tbitmap;//设置一个图形变量
begin
bmp:=tbitmap.Create;
bmp.Width:=rect.Right+10;
bmp.Height:=rect.Bottom+10;
bmp.canvas.CopyRect(rect,sdiappform.canvas,rect);
clipboard.Assign(bmp);
bmp.free;
end;
//从剪贴板上复制
procedureTSDIAppForm.EditPaste1Execute(Sender:TObject);
var
bmp:tbitmap;//设置一个图形变量
begin
ifclipboard.HasFormat(CF_BITMAP)then
begin
bmp:=tbitmap.create;
bmp.Assign(clipboard);
sdiappform.Canvas.draw(0,0,bmp);
bmp.free;
end
elseifclipboard.HasFormat(CF_TEXT)then
begin
str:=clipboard.AsText;
detectI:=0;
invalidate;
end;
end;
//剪下图形拷贝到剪贴板
procedureTSDIAppForm.EditCut1Execute(Sender:TObject);
begin
EditCopy1Execute(sender);
withsdiappform.Canvasdo
begin
copymode:=cmwhiteness;
copyRect(rect,sdiappform.Canvas,rect);
CopyMode:=cmSrcCopy;
end;
end;
procedureTSDIAppForm.FileOpen1Execute(Sender:TObject);
var
bmp:Tbitmap;
currentfile:string;
begin
ifOpenDialog.Executethen
begin
currentfile:=OpenDialog.filename;
ifcurrentfile$#@60;$#@62;then
try
bmp:=tbitmap.Create;
bmp.LoadFromFile(currentfile);
sdiappform.Canvas.StretchDraw(rect,bmp);
finally
bmp.Free;
end;
end;
end;
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。