这个是我自己写的组件,存在刷新问题比如:
第一张图片:我先在CAPTION中写入‘11111’ 然后再写‘测试测试’就出现第一张图片里的情况
第三张图片:我把组件放在D7里 然后切换到桌面或浏览器,再倒回去就出现图片三的情况
我想请教这些问题该怎么解决?应该是刷新问题!!!!
解决方案 »
- ◆◆◆◆ Image.Canvas的图形放大缩小问题!◆◆◆◆ -------------急 在线等待●●●●●
- 欢迎赐教....
- 急死了,急需一个身份证式的套打(DELPHI6)
- 关于POSTERROR的一个小问题
- 如何获得dbexpress操作interbase和oracle数据库的错误代码?
- 在做一个学生管理系统遇到的问题,请指教!
- (300分送上)第三次提问 怎样查找得到某个共享文件夹内 所有文件(包括子文件夹)的所有文件名。
- 用delphi接收由net send发送的信息,即如何用DELPHI编程实现信息使服务来接收net send发来的信息?
- DLL注入后,如何让目标程序执行DLL里的函数
- 怎样将JPG文件转为BMP文件???
- 元旦快乐+新年快乐
- 求助~~delphi 最简单的3层结构~~纠结了2天了!!!!求大侠!!!!
Windows,
SysUtils,
Messages,
Classes,
Graphics,
Controls;type
TAreaTexto=record
Width:Integer;
Height:Integer;
end; TButtonBitmaps = class( TPersistent )
private
FUp: TBitmap;
FDown: TBitmap;
FHot: TBitmap;
protected
procedure SetUp( Value: TBitmap ); virtual;
procedure SetDown( Value: TBitmap ); virtual;
procedure SetHot( Value: TBitmap ); virtual;
public
constructor Create;
destructor Destroy; override;
published
property Down: TBitmap
read FDown
write SetDown;
property Hot: TBitmap
read FHot
write SetHot;
property Up: TBitmap
read FUp
write SetUp;
end; TImgButton = class(TCustomControl)
private
FCaption:TCaption;
FBitmaps: TButtonBitmaps;
FCanvas:TCanvas;
IsFocused: Boolean;
function GetTextLength(st:String):TAreaTexto;
procedure SetCaption(value: TCaption);
procedure WMSetFocus( var msg: TWMSetFocus ); message wm_SetFocus;
procedure WMKillFocus( var msg: TWMKillFocus ); message wm_KillFocus;
procedure WMSize( var msg: TWMSize ); message wm_Size;
procedure CMFontChanged( var Msg: TMessage ); message cm_FontChanged; //更改Font时触发消息
procedure CMTextChanged( var Msg: TMessage ); message cm_TextChanged; //文字变化触发消息
procedure CMSysColorChange( var Msg: TMessage ); message cm_SysColorChange;
procedure CMMouseEnter( var Msg: TMessage ); message cm_MouseEnter;
procedure CMMouseLeave( var Msg: TMessage ); message cm_MouseLeave;
procedure WMEraseBkgnd( var Msg: TWMEraseBkgnd ); message wm_EraseBkgnd;
protected
procedure Paint; override;
public
constructor Create( AOwner: TComponent ); override;
destructor Destroy; override;
published
property Bitmaps: TButtonBitmaps read FBitmaps write FBitmaps;
property Caption: TCaption read FCaption Write SetCaption;
property Enabled;
property Font;
property ParentFont;
property Visible;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('TImgButton', [TImgButton]);
end;{==============================}
{== TButtonBitmaps Methods ==}
{==============================}constructor TButtonBitmaps.Create;
begin
FUp := TBitmap.Create;
FDown := TBitmap.Create;
FHot := TBitmap.Create;
end;destructor TButtonBitmaps.Destroy;
begin
FUp.Free;
FDown.Free;
FHot.Free;
inherited;
end;procedure TButtonBitmaps.SetUp( Value: TBitmap );
begin
FUp.Assign( Value );
end;procedure TButtonBitmaps.SetDown( Value: TBitmap );
begin
FDown.Assign( Value );
end;procedure TButtonBitmaps.SetHot( Value: TBitmap );
begin
FHot.Assign( Value );
end;{==========================}
{== TImgButton Methods ==}
{==========================}
constructor TImgButton.Create( AOwner: TComponent );
begin
inherited;
Width := 80;
Height := 30;
ControlStyle := [ csCaptureMouse, csOpaque, csDoubleClicks ];
FBitmaps := TButtonBitmaps.Create;
FCanvas := TControlCanvas.Create;
TControlCanvas(FCanvas).Control := Self;
IsFocused := False;
end;
destructor TImgButton.Destroy;
begin
FBitmaps.Free;
FCanvas.Free;
inherited;
end;function TImgButton.GetTextLength(st:String):TAreaTexto;
begin
// canvas.Font.Assign(FFont);
result.Width:=canvas.TextWidth(st);
result.Height:=canvas.TextHeight(st);
end;procedure TImgButton.Paint;
Var
a:TAreaTexto;
begin
inherited Paint;
a:=GetTextLength(FCaption);
FCanvas.Brush.Style:=bsClear;
//Rect := GetClientRect;
//绘制标题
FCanvas.TextOut((width div 2)-(a.Width div 2),Height-(a.Height+2),FCaption);
end;procedure TImgButton.CMFontChanged( var Msg: TMessage );
begin
Invalidate;
end;procedure TImgButton.CMTextChanged( var Msg: TMessage );
begin
Invalidate;
end;procedure TImgButton.CMSysColorChange( var Msg: TMessage );
begin
Invalidate;
end;procedure TImgButton.WMSetFocus( var msg: TWMSetFocus );
begin
inherited;
IsFocused := True;
Invalidate;
end;procedure TImgButton.WMKillFocus( var msg: TWMKillFocus );
begin
inherited;
IsFocused := False;
Invalidate;
end;procedure TImgButton.WMSize( var msg: TWMSize );
begin
if csLoading in ComponentState then Exit;
end;procedure TImgButton.CMMouseEnter( var Msg: TMessage );
begin
if csDesigning in ComponentState then Exit;
end;procedure TImgButton.CMMouseLeave( var Msg: TMessage );
begin
inherited;
end;procedure TImgButton.WMEraseBkgnd( var Msg: TWMEraseBkgnd );
begin
Msg.Result := 1;
end;procedure TImgButton.SetCaption(value: TCaption);
begin
Fcaption:=Value;
repaint;
end;
end.