在form上画的graph被覆盖后就消失的问题(50分)

  • 主题发起人 主题发起人 yxbhw
  • 开始时间 开始时间
Y

yxbhw

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);
begin
SetClassLong(Form1.Handle,GCL_STYLE,GetClassLong(Form1.Handle,GCL_STYLE) or CS_SAVEBITS);
Form1.Canvas.Brush.Color :=ClRed;
Form1.Canvas.Rectangle(10,10,100,100);
end;
end.
修改Form的窗口类属性,使该窗口重绘时从保存的位图中更新,怎么试都没有成功。
怎么回事?
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
bIfDraw: Boolean;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
{ 判断是否画了 }
bIfDraw := false;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
SetClassLong(Form1.Handle, GCL_STYLE, GetClassLong(Form1.Handle, GCL_STYLE) or CS_SAVEBITS);
Form1.Canvas.Brush.Color := ClRed;
Form1.Canvas.Rectangle(10, 10, 100, 100);
bIfDraw := true;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
if bIfDraw then
begin
Form1.Canvas.Brush.Color := ClRed;
Form1.Canvas.Rectangle(10, 10, 100, 100);
end;
end;

end.
 
i agree with 小笨笨
 
如果我在窗体上放一个StringGrid,在其中画图。
按"小笨苯"的方法,窗体上的图块可以通过,但网格内的图块刷新总是慢半拍。
我问这个问题的重要目的是为了在StringGrid中填充颜色,
画各种颜色的网格线,使数据看起来有条理。有知道方法的请不吝赐教,谢谢大家!
procedure TForm1.FormCreate(Sender: TObject);
begin
{ 判断是否画了 }
bIfDraw := false;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Canvas.Brush.Color := ClRed;
Form1.Canvas.Rectangle(10, 10, 100, 100);
StringGrid1.Canvas.Brush.Color:=clred;
StringGrid1.Canvas.Rectangle(10,10,100,100);
bIfDraw := true;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
if bIfDraw then
begin
Form1.Canvas.Brush.Color := ClRed;
Form1.Canvas.Rectangle(10, 10, 100, 100);
stringgrid1.Canvas.Brush.Color:=clred;
stringgrid1.Canvas.Rectangle(10,10,100,100);
end;
end;
 
接受答案了.
 
后退
顶部