这个是我自己写的组件,存在刷新问题比如:
第一张图片:我先在CAPTION中写入‘11111’  然后再写‘测试测试’就出现第一张图片里的情况
第三张图片:我把组件放在D7里 然后切换到桌面或浏览器,再倒回去就出现图片三的情况
我想请教这些问题该怎么解决?应该是刷新问题!!!!

解决方案 »

  1.   

    重写组件的刷新代码,image本身无法进行刷新,是依靠其parent来刷新自己
      

  2.   

    小弟刚学组件编写 写的不好 还望各位不要取笑!unit ImgButton;interfaceuses
      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.