L
landy2005t
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
DrawShape(Origin, Point(X, Y), pmCopy); { draw the final shape }
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if ssLeft in Shift then
begin
DrawShape(Origin, Point(X,Y), pmNotXor); { erase the previous shape }
MovePt := Point(X, Y); { record the current point }
DrawShape(Origin, MovePt, pmNotXor); { draw the current shape }
end else
Origin:=Point(X,Y);
end;
procedure TForm1.LineButtonClick(Sender: TObject); { LineButton }
begin
DrawingTool := dtLine;
end;
procedure TForm1.RectangleButtonClick(Sender: TObject); { RectangleButton }
begin
DrawingTool := dtRectangle;
end;
procedure TForm1.EllipseButtonClick(Sender: TObject); { EllipseButton }
begin
DrawingTool := dtEllipse;
end;
procedure TForm1.RoundedRectClick(Sender: TObject); { RoundRectButton }
begin
DrawingTool := dtRoundRect;
end;
procedure TForm1.DrawShape(TopLeft, BottomRight: TPoint; AMode: TPenMode);
begin
with Canvas do
begin
Pen.Mode := AMode;
case DrawingTool of
dtLine:
begin
MoveTo(TopLeft.X, TopLeft.Y);
LineTo(BottomRight.X, BottomRight.Y);
end;
dtRectangle:Rectangle(TopLeft.X, TopLeft.Y,BottomRight.X, BottomRight.Y);
dtEllipse: Ellipse(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
dtRoundRect: RoundRect(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y,
(TopLeft.X - BottomRight.X) div 2, (TopLeft.Y - BottomRight.Y) div 2);
end;
end;
end;
end.
下面三句代码总是不明白。
begin
DrawShape(Origin, Point(X,Y), pmNotXor); { erase the previous shape }
MovePt := Point(X, Y); { record the current point }
DrawShape(Origin, MovePt, pmNotXor); { draw the current shape
这三句中第一句是擦除当前的图形第二句是,第二句是保存当前点第三句画当前的图。
好像第一句和第三句是一样的啊我不知道有什么用?
pmnotxor是什么意思,还有前面的pmcopy是什么意思,为什么还要在鼠标松开的事件中再编写画图一次呢?想了半天没有答案望大侠帮帮我尽量详细,小弟感之不尽。
还有怎么样编写一个在文本框只准输入数字的程序我编了可是不对如下。
if not (key in p['0'..'9',#13,#8]) then
key:=#0;
可是key是word类型的也编不通过我用char(key) in 然后再key:=0; 一样字母也可以输入望指教万分感谢。
Shift: TShiftState; X, Y: Integer);
begin
DrawShape(Origin, Point(X, Y), pmCopy); { draw the final shape }
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if ssLeft in Shift then
begin
DrawShape(Origin, Point(X,Y), pmNotXor); { erase the previous shape }
MovePt := Point(X, Y); { record the current point }
DrawShape(Origin, MovePt, pmNotXor); { draw the current shape }
end else
Origin:=Point(X,Y);
end;
procedure TForm1.LineButtonClick(Sender: TObject); { LineButton }
begin
DrawingTool := dtLine;
end;
procedure TForm1.RectangleButtonClick(Sender: TObject); { RectangleButton }
begin
DrawingTool := dtRectangle;
end;
procedure TForm1.EllipseButtonClick(Sender: TObject); { EllipseButton }
begin
DrawingTool := dtEllipse;
end;
procedure TForm1.RoundedRectClick(Sender: TObject); { RoundRectButton }
begin
DrawingTool := dtRoundRect;
end;
procedure TForm1.DrawShape(TopLeft, BottomRight: TPoint; AMode: TPenMode);
begin
with Canvas do
begin
Pen.Mode := AMode;
case DrawingTool of
dtLine:
begin
MoveTo(TopLeft.X, TopLeft.Y);
LineTo(BottomRight.X, BottomRight.Y);
end;
dtRectangle:Rectangle(TopLeft.X, TopLeft.Y,BottomRight.X, BottomRight.Y);
dtEllipse: Ellipse(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
dtRoundRect: RoundRect(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y,
(TopLeft.X - BottomRight.X) div 2, (TopLeft.Y - BottomRight.Y) div 2);
end;
end;
end;
end.
下面三句代码总是不明白。
begin
DrawShape(Origin, Point(X,Y), pmNotXor); { erase the previous shape }
MovePt := Point(X, Y); { record the current point }
DrawShape(Origin, MovePt, pmNotXor); { draw the current shape
这三句中第一句是擦除当前的图形第二句是,第二句是保存当前点第三句画当前的图。
好像第一句和第三句是一样的啊我不知道有什么用?
pmnotxor是什么意思,还有前面的pmcopy是什么意思,为什么还要在鼠标松开的事件中再编写画图一次呢?想了半天没有答案望大侠帮帮我尽量详细,小弟感之不尽。
还有怎么样编写一个在文本框只准输入数字的程序我编了可是不对如下。
if not (key in p['0'..'9',#13,#8]) then
key:=#0;
可是key是word类型的也编不通过我用char(key) in 然后再key:=0; 一样字母也可以输入望指教万分感谢。