Delphi7 图像篇(三)
2020-12-13 15:37
标签:style blog http io color ar os for sp 本实例主要用鼠标在窗体上绘图 用到组件有TBevel、TRadioGroup、TButton组件 运行效果如下: Delphi7 图像篇(三) 标签:style blog http io color ar os for sp 原文地址:http://www.cnblogs.com/delphi2014/p/4076135.htmlunit Unit1;
interface
uses
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)
下一篇:Java程序特性