关于Repaint ( 积分: 5 )

  • 主题发起人 主题发起人 del_today
  • 开始时间 开始时间
D

del_today

Unregistered / Unconfirmed
GUEST, unregistred user!
请问各位高手:
在下列程序中,语句“PaintBox1.Repaint;”是否调用过程
“procedure TForm1.PaintBox1Paint(Sender: TObject);”???

procedure TForm1.FormCreate(Sender: TObject);
begin
Shape:=4;
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
With Sender as TPaintBox do
if Shape=1 then
begin
Canvas.Pen.Color:=clBlack;
Canvas.Ellipse(0,0,30,30);
end
else begin
if shape=2 then
begin
Canvas.Pen.Color:=clRed;
Canvas.PolyLine([Point(40,10),Point(20,60),
Point(70,30),Point(10,30),Point(60,60),Point(40,10)]);
end
else
begin
if shape=3 then
begin
Canvas.Pen.Color:=clBlue;
Canvas.Rectangle(0,0,30,30);
end;
end;
end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
Shape:=1;
PaintBox1.Repaint;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Shape:=2;
PaintBox1.Repaint;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Shape:=3;
PaintBox1.Repaint;
end;

end.
 
请问各位高手:
在下列程序中,语句“PaintBox1.Repaint;”是否调用过程
“procedure TForm1.PaintBox1Paint(Sender: TObject);”???

procedure TForm1.FormCreate(Sender: TObject);
begin
Shape:=4;
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
With Sender as TPaintBox do
if Shape=1 then
begin
Canvas.Pen.Color:=clBlack;
Canvas.Ellipse(0,0,30,30);
end
else begin
if shape=2 then
begin
Canvas.Pen.Color:=clRed;
Canvas.PolyLine([Point(40,10),Point(20,60),
Point(70,30),Point(10,30),Point(60,60),Point(40,10)]);
end
else
begin
if shape=3 then
begin
Canvas.Pen.Color:=clBlue;
Canvas.Rectangle(0,0,30,30);
end;
end;
end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
Shape:=1;
PaintBox1.Repaint;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Shape:=2;
PaintBox1.Repaint;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Shape:=3;
PaintBox1.Repaint;
end;

end.
 
单步跟踪一下,不就知道了。
 
严格来说repaint不会调用OnPaint事件. OnPaint事件是由windows的WM_PAINT消息或form的PaintTo方法调用的, 只不过正常情况下Repaint会触发windows产生WM_PAINT消息而已.

要证明它们没有调用关系很简单, 只要这个窗被其它窗口完全遮挡情况下调用repaint就可以知道根本不会调用到OnPaint事件
 

Similar threads

I
回复
0
查看
580
import
I
I
回复
0
查看
701
import
I
I
回复
0
查看
648
import
I
I
回复
0
查看
777
import
I
I
回复
0
查看
542
import
I
后退
顶部