我在一个窗体上放置一个PaintBox 控件和一个Image 控件,然后在每一个里面生成画出一幅图片,随后用鼠标在里面画线,但在PaintBox 里面画线时不出现闪烁,而在Image 里面画线时,就有一横线闪烁出现,我实在弄不明白,请高手赐教,在此非常感谢!!现将源代码列在下面,请你们自己试一下。首先,点DRAW按钮,再在上面画线,对比一下,看出现什么情况。type
  TForm1 = class(TForm)
    Button1: TButton;
    PaintBox1: TPaintBox;
    Image1: TImage;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
    pOrgx,pOrgy,pLastx,pLasty:integer;
    done:Boolean;
    pOrgx1,pOrgy1,pLastx1,pLasty1:integer;
    done1:Boolean;
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
  aa:TBitmap;
  i,j:integer;
begin
  aa:=tbitmap.Create;
   try
     aa.Width:=200;
     aa.Height:=200;
     aa.pixelformat:=pf8bit;
     for i:=0 to 199 do
       for j:=0 to 199 do
         aa.Canvas.Pixels[j,i]:=clRed;
     PaintBox1.Width:=200;
     PaintBox1.Height:=200;
     image1.Width:=200;
     image1.Height:=200;
     PaintBox1.Canvas.Draw(0,0,aa);
     image1.Canvas.Draw(0,0,aa);
   finally
     aa.Free;
   end;
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
   if (Button=mbLeft) then
   begin
      done1:=TRUE;
      pOrgx1:=X;
      pOrgy1:=Y;
      pLastx1:=X;
      pLasty1:=Y;
   end;
end;procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
 if shift=[ssLeft] then
   if done1 then
   begin
     image1.canvas.pen.mode:=pmnot;
     if (pLastx1<>-1) and (pLasty1<>-1) then
     begin
       image1.canvas.moveto(pOrgx1,pOrgy1);
       image1.canvas.lineto(pLastx1,pLasty1);
     end;
     image1.canvas.moveto(pOrgx1,pOrgy1);
     image1.canvas.lineto(X,Y);
     pLastx1:=X;
     pLasty1:=Y;
   end;
end;procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 if  done1 and (Button=mbLeft) then
 begin
   image1.canvas.pen.mode:=pmNop;
   image1.canvas.moveto(pOrgx1,pOrgy1);
   image1.canvas.lineto(X,Y);
   done1:=FALSE;
 end;
end;procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
   if (Button=mbLeft) then
   begin
      done1:=TRUE;
      pOrgx1:=X;
      pOrgy1:=Y;
      pLastx1:=X;
      pLasty1:=Y;
   end;
end;procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
 if shift=[ssLeft] then
   if done1 then
   begin
     PaintBox1.canvas.pen.mode:=pmnot;
     if (pLastx1<>-1) and (pLasty1<>-1) then
     begin
       PaintBox1.canvas.moveto(pOrgx1,pOrgy1);
       PaintBox1.canvas.lineto(pLastx1,pLasty1);
     end;
     PaintBox1.canvas.moveto(pOrgx1,pOrgy1);
     PaintBox1.canvas.lineto(X,Y);
     pLastx1:=X;
     pLasty1:=Y;
   end;
end;procedure TForm1.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 if  done1 and (Button=mbLeft) then
 begin
   PaintBox1.canvas.pen.Mode:=pmNop;
   PaintBox1.canvas.moveto(pOrgx1,pOrgy1);
   PaintBox1.canvas.lineto(X,Y);
   done1:=FALSE;
 end;
end;到此结束。