Image为什么会闪动? 图片可能太大了,load的时候会有闪东。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 继承自TWinControl的控件好像都可以自动出发OnPaint事件,有一个办法可以解决,就是不重画背景。这有个俄国佬写的小例子,大家可以借鉴一下:unit FFPBox;{=======================================================}interface{=======================================================}uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls;type TFFPaintEvent = procedure (Sender: TObject; Canvas: TCanvas) of Object; TFlickerFreePaintBox = class(TCustomControl) private { Private declarations } FOnFFPaint:TFFPaintEvent; protected { Protected declarations } procedure Paint; override; procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND; public { Public declarations } constructor Create(AOwner: TComponent); override; published { Published declarations } property OnPaint:TFFPaintEvent read FOnFFPaint write FOnFFPaint; property Align; property Color; property DragCursor; property DragMode; property Enabled; property Font; property ParentColor; property ParentFont; property ParentShowHint; property PopupMenu; property ShowHint; property Visible; property OnClick; property OnDblClick; property OnDragDrop; property OnDragOver; property OnEndDrag; property OnMouseDown; property OnMouseMove; property OnMouseUp; property OnStartDrag; end;procedure Register;{=======================================================}implementation{=======================================================}constructor TFlickerFreePaintBox.Create(AOwner: TComponent);begin inherited Create(AOwner); TabStop := False;end;{-------------------------------------------------------}procedure TFlickerFreePaintBox.Paint;var bmp: TBitmap;begin if csDesigning in ComponentState then with Canvas do begin Pen.Style := psDash; Brush.Style := bsSolid; Canvas.Brush.Color := Color; Rectangle(0, 0, Width, Height); exit; end; bmp := TBitmap.Create; try bmp.Canvas.Brush.Color := Color; bmp.Width := Width; bmp.Height := Height; bmp.Canvas.Font := Font; if Assigned(FOnFFPaint) then begin FOnFFPaint(Self, bmp.Canvas); Canvas.Draw(0,0, bmp); end; finally bmp.Free; end;end;{-------------------------------------------------------}{------------------------关键之处-----------------------}procedure TFlickerFreePaintBox.WMEraseBkgnd(var Message: TWMEraseBkgnd);begin Message.Result := 1;end;{=======================================================}procedure Register;begin RegisterComponents('System', [TFlickerFreePaintBox]);end;end. DoubleBuffered:=True;可能有用 同一单元类之间的相互引用问题 用webbrowser做隔浏览器,如何让在此浏览器中运行的网页自动全部最大化 如何在dbgrideh中的合计栏里得到显示的值 STRING TO PCHAR 如何在Delphi程序中获取局域网中相关指定IP地址的计算机的硬盘,CPU,内存的使用情况? 送分啊! 用D5编的人事系统程序可以在D6里打开吗? 不会使用网上的控件,谁教我? 我用delphi6。0做了一个东东,但不知道怎么生成.exe文件,请教? 想问大家一个数据显示的小问题! 如何动态在form中创建label,并且显示? 请问
这有个俄国佬写的小例子,大家可以借鉴一下:
unit FFPBox;
{=======================================================}
interface
{=======================================================}
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;type
TFFPaintEvent = procedure (Sender: TObject; Canvas: TCanvas) of Object; TFlickerFreePaintBox = class(TCustomControl)
private
{ Private declarations }
FOnFFPaint:TFFPaintEvent;
protected
{ Protected declarations }
procedure Paint; override;
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
property OnPaint:TFFPaintEvent read FOnFFPaint write FOnFFPaint;
property Align;
property Color;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Visible;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
end;procedure Register;
{=======================================================}
implementation
{=======================================================}
constructor TFlickerFreePaintBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
TabStop := False;
end;
{-------------------------------------------------------}
procedure TFlickerFreePaintBox.Paint;
var bmp: TBitmap;
begin
if csDesigning in ComponentState then
with Canvas do
begin
Pen.Style := psDash;
Brush.Style := bsSolid;
Canvas.Brush.Color := Color;
Rectangle(0, 0, Width, Height);
exit;
end; bmp := TBitmap.Create;
try
bmp.Canvas.Brush.Color := Color;
bmp.Width := Width;
bmp.Height := Height;
bmp.Canvas.Font := Font;
if Assigned(FOnFFPaint) then begin
FOnFFPaint(Self, bmp.Canvas);
Canvas.Draw(0,0, bmp);
end;
finally
bmp.Free;
end;
end;
{-------------------------------------------------------}
{------------------------关键之处-----------------------}
procedure TFlickerFreePaintBox.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
Message.Result := 1;
end;
{=======================================================}
procedure Register;
begin
RegisterComponents('System', [TFlickerFreePaintBox]);
end;end.
可能有用