大侠求你们帮帮我一个画图问题我研究一天了头都痛了,求你们我是穷人。 ( 积分: 10 )

  • 主题发起人 主题发起人 landy2005t
  • 开始时间 开始时间
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; 一样字母也可以输入望指教万分感谢。
 
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; 一样字母也可以输入望指教万分感谢。
 
type TPenMode = (pmBlack, pmWhite, pmNop, pmNot, pmCopy, pmNotCopy, pmMergePenNot, pmMaskPenNot, pmMergeNotPen, pmMaskNotPen, pmMerge, pmNotMerge, pmMask, pmNotMask, pmXor, pmNotXor);

pmCopy Pen color specified in Color property
pmNotXor Inverse of pmXor: combination of colors in either pen or canvas background, but not both
{===========================================================================}
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9', #13, #8]) then
key := #0;
end;
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
927
SUNSTONE的Delphi笔记
S
L
回复
9
查看
501
lisuju
L
后退
顶部