首页 > 代码库 > Delphi7 图像篇(三)
Delphi7 图像篇(三)
本实例主要用鼠标在窗体上绘图
用到组件有TBevel、TRadioGroup、TButton组件
运行效果如下:
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, XPMan;type TForm1 = class(TForm) Bevel1: TBevel; Bevel2: TBevel; Bevel3: TBevel; Bevel4: TBevel; Button1: TButton; RadioGroup1: TRadioGroup; Button2: TButton; procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private start:Boolean; OX,OY:Integer; { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin start:=true; case RadioGroup1.ItemIndex of 0: ; //nothing 1,2,3,4, 5: begin OX:=X; OY:=Y; end; end; Self.Canvas.MoveTo(X,Y); //设置画笔的起始位置end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);begin if start then begin case RadioGroup1.ItemIndex of //根据TRadioGroup组件的索引号进行操作 0: begin Canvas.Pen.Color := clWindowText; //将画笔设置成黑色 self.Canvas.LineTo(X,Y); //鼠标移动时在窗体上画线 end; 1,2,3,4: Canvas.Pen.Color := clWindowText; //将画笔设置成黑色 5: begin Canvas.Pen.Color := form1.Color; //将画笔颜色设置成窗体颜色 Canvas.Brush.Color := form1.Color; //将画刷颜色设置成窗体颜色 Canvas.Rectangle(X-2,Y-2,X+2,Y+2); //对窗体进行擦除 end; end; end;end;procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin start:=false; case RadioGroup1.ItemIndex of 0: ; 1: Canvas.Arc(OX,OY,x,y,oX,oY,X,y); //画弧形 2: Canvas.Ellipse(Rect(OX,OY,x,y)); //画椭圆 3: Canvas.Rectangle(OX,OY,x,y); //画矩形 4: begin //画椭圆 if abs(x-OX)<abs(y-OY) then Canvas.Ellipse(OX,OY,OX+abs(OX-x),OY+abs(OX-x)) //以X值的长度画椭圆 else Canvas.Ellipse(OX,OY,OX+abs(OY-y),OY+abs(OY-y)); //以Y值的长度画椭圆 end; end;end;procedure TForm1.Button2Click(Sender: TObject);begin Close;end;procedure TForm1.Button1Click(Sender: TObject);begin form1.canvas.FillRect(Rect(9,9,392,288));end;end.
Delphi7 图像篇(三)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。