{****************************************}
{Bresenham,the line paint }
{Designed by whbo,copyright (c) 2003-2004}
{Get in touch with me .Tel:07102690635 }
{email:[email protected] }
{****************************************}
unit unitline;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
Tlinefrm = class(TForm)
Button1: TButton;
input1: TEdit;
input3: TEdit;
StaticText1: TStaticText;
StaticText2: TStaticText;
input2: TEdit;
input4: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure input1KeyPress(Sender: TObject; var Key: Char);
procedure input2KeyPress(Sender: TObject; var Key: Char);
procedure input3KeyPress(Sender: TObject; var Key: Char);
procedure input4KeyPress(Sender: TObject; var Key: Char);
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
linefrm: Tlinefrm;
implementation
uses unitshow;
{$R *.dfm}
procedure Tlinefrm.Button1Click(Sender: TObject);
var
x0,y0,x1,y1,x,y,i,dx,dy,e:integer;
//x0,y0是起点,x1,y1是终点,x,y做循环是用。
begin
showfrm.Visible:=true;
showfrm.Show;
if (input1.Text <>'') and (input2.Text <>'') and (input3.Text <>'') and (input4.Text <>'') then
begin
x1:=strtoint(input3.Text);
y1:=strtoint(input4.Text);
x0:=strtoint(input1.Text);
y0:=strtoint(input2.Text);
dx:=x1-x0;
dy:=y1-y0;
e:=-dx;
x:=x0;
y:=y0;
for i:=0 to dy do
begin
showfrm.Canvas.Pixels[x,y]:=clred;
x:=x+1;
e:=e+2*dy;
if(e>=0) then
begin
y:=y+1;
e:=e-2*dx;
end;
end;
end;
if (input1.Text ='') or (input2.Text ='') or(input3.Text ='') or (input4.Text ='') then
begin
showmessage('没有数据输入');
showfrm.Visible:=false;
end;
end;
procedure Tlinefrm.input1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
input2.SetFocus;
end;
procedure Tlinefrm.input2KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
input3.SetFocus;
end;
procedure Tlinefrm.input3KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
input4.SetFocus;
end;
procedure Tlinefrm.input4KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
button1.SetFocus;
end;
procedure Tlinefrm.FormShow(Sender: TObject);
begin
input1.SetFocus;
showfrm.Visible:=false;
end;
procedure Tlinefrm.Button2Click(Sender: TObject);
var i:integer;
begin
for i:=0 to componentcount-1 do
begin
if components[i] is Tedit then
Tedit(components[i]).Text:='';
end;
end;
end.
本文地址:http://com.8s8s.com/it/it33166.htm