D
Dlwxn
Unregistered / Unconfirmed
GUEST, unregistred user!
子窗体上有ScrollBox,将PaintBox放在ScrollBox上,在PaintBox的MouseDown、MouseUp、MouseMove事件中绘图,但当有多个子窗体时,如果在一个子窗体上绘图时其它的子窗体上也同时绘出同样的图形,我要在不同的子窗体上绘不同的图形。
我的程序比较复杂,为了说明这个问题,我做了一个简单的,又发现了一个新的问题,当有两个子窗体,在第一个子窗体上绘图,如果将另一个子窗体从第一个子窗体上移过,刚画的图形被檫除,以下是我的代码,这是怎么回事,最好能回答我的上面的问题。先谢谢!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
New1: TMenuItem;
procedure New1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses unit2;
{$R *.dfm}
procedure TForm1.New1Click(Sender: TObject);
begin
TForm2.Create(Application) ;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm2 = class(TForm)
ScrollBox1: TScrollBox;
PaintBox1: TPaintBox;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
Drawing:boolean;
implementation
{$R *.dfm}
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=caFree;
end;
procedure TForm2.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Drawing:=true;
PaintBox1.Canvas.Pen.Mode:=pmNotXor;
PaintBox1.Canvas.MoveTo(x,y);
end;
procedure TForm2.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Drawing:=false;
end;
procedure TForm2.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Drawing then
PaintBox1.Canvas.LineTo(x,y);
end;
end.
我的程序比较复杂,为了说明这个问题,我做了一个简单的,又发现了一个新的问题,当有两个子窗体,在第一个子窗体上绘图,如果将另一个子窗体从第一个子窗体上移过,刚画的图形被檫除,以下是我的代码,这是怎么回事,最好能回答我的上面的问题。先谢谢!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
New1: TMenuItem;
procedure New1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses unit2;
{$R *.dfm}
procedure TForm1.New1Click(Sender: TObject);
begin
TForm2.Create(Application) ;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm2 = class(TForm)
ScrollBox1: TScrollBox;
PaintBox1: TPaintBox;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
Drawing:boolean;
implementation
{$R *.dfm}
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=caFree;
end;
procedure TForm2.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Drawing:=true;
PaintBox1.Canvas.Pen.Mode:=pmNotXor;
PaintBox1.Canvas.MoveTo(x,y);
end;
procedure TForm2.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Drawing:=false;
end;
procedure TForm2.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Drawing then
PaintBox1.Canvas.LineTo(x,y);
end;
end.