MDI的画图问题

Dlwxn 2003-08-14 09:39:19
子窗体上有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.

...全文
44 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
feidaoking 2003-08-18
  • 打赏
  • 举报
回复
是的,我也碰到有窗体在图形上移动后,图像就被擦除了,问怎么解决这个问题阿
Dlwxn 2003-08-18
  • 打赏
  • 举报
回复
做出来了,多谢提醒!
Dlwxn 2003-08-18
  • 打赏
  • 举报
回复
风大侠,就因为我把在OnMouseDown、OnMouseUp、OnMouseMove绘出的各种图形都记录下来,然后在PaintBox 的 OnPaint 重画图形,所有子窗体的PaintBox 的 OnPaint、OnMouseDown、OnMouseUp、OnMouseMove 代码都是一样的,才在不同的子窗体中画出同样的图形。

有点问题不明白:用双DC能解决三个或三个以上子窗体同时绘图中出现的所有的子窗体中绘出同样的图形吗?

至于上面例子中的移动后图像被擦出,我已经搞定。

Dlwxn 2003-08-15
  • 打赏
  • 举报
回复
up
Dlwxn 2003-08-15
  • 打赏
  • 举报
回复
先试一下,我的图形是矢量图,稍微麻烦一点。
firetoucher 2003-08-15
  • 打赏
  • 举报
回复
用双DC或者自己处理WM_PAINT,或者直接调用InvalidateRect迫使窗口重画。

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧