能不能在 hint 里加图片?

解决方案 »

  1.   

    在Delphi7中, 新建一张Form, 加入图片. 然后设置Form的半透明度.最后在要调用时手工显示或隐含这张Form, 就达到Hint的效果.
      

  2.   

    以下方法把所有的Hint以椭圆形显示
    修改以下的语句DrawText(Canvas.Handle , PChar(Caption),Length(Caption),R,DT_NOPREFIX or DT_WORDBREAK or DT_CENTER or DT_VCENTER)
    变成画图语句,应该能画出图片。
    在其他单元中uses这个单元即可unit MyHintwindow;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
      TMyHintwindow = class(THintwindow)
      private
         FRegion :THandle ;
         procedure FreeCurrentRegion ;
        { Private declarations }
      protected
        { Protected declarations }
      public
         destructor Destroy;override ;
         procedure ActivateHint(Rect:TRect;const AHint:string);override ;
         procedure paint ;override ;
         procedure CreateParams(var Params:TCreateParams);override ;
        { Public declarations }
      published
        { Published declarations }
      end;//procedure Register;implementationdestructor TMyHintwindow.Destroy ;
    begin
       FreeCurrentRegion ;
       inherited Destroy ;
    end ;procedure TMyHintwindow.FreeCurrentRegion;
    begin
       if FRegion <> 0 then
       begin
          SetWindowRgn(Handle , 0 , True );
          DeleteObject(FRegion) ;
          FRegion := 0 ;
       end ;
    end ;procedure TMyHintwindow.ActivateHint(Rect:TRect;const AHint:String) ;
    begin
       with Rect do Right := Right + Canvas.TextWidth('WWWW') ;
       BoundsRect := Rect ;
       FreeCurrentRegion ;
       with BoundsRect do
          FRegion := CreateRoundRectRgn(0,0,Width,Height,Width,Height);
       if FRegion <> 0 then
          SetWindowRgn(Handle,FRegion,True);
       inherited ActivateHint(Rect,AHint) ;
    end ;procedure TMyHintwindow.CreateParams(var Params:TCreateParams);
    begin
       inherited CreateParams(Params) ;
       Params.Style := Params.Style and ws_Border ;
    end ;procedure TMyHintwindow.paint ;
    var R:TRect ;
    begin
       R := ClientRect ;
       Inc(R.Left,1) ;
       //Canvas.Font.Color := clInfoText ;
       Canvas.brush.Color := clYellow ;
       Canvas.Font.Color := clBlue ;
       DrawText(Canvas.Handle , PChar(Caption),Length(Caption),R,
          DT_NOPREFIX or DT_WORDBREAK or DT_CENTER or DT_VCENTER);
    end ;
    {procedure Register;
    begin
      RegisterComponents('Standard', [TMyHintwindow]);
    end;   }initialization
       Application.ShowHint := false ;
       HintWindowClass := TMyHintWindow ;
       Application.ShowHint := True ;end.