http://www.ten-design.net/c.jpgGrid列宽度不够时,出现提示框。谢谢。

解决方案 »

  1.   

    恰巧我做过,非常容易
    自己做个Grid控件,从StringGrid继承
    uses
      forms;type 
      TLssStringGrid = class(TStringGrid)
      private
        FLastHintPos: TPoint;
        procedure CMHintShow(var Msg: TMessage); message CM_HINTSHOW;  protected
        procedure ShowHintProc(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
        procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
      end;//实现部分Procedure TLssStringGrid.CMHintShow(Var Msg: TMessage);
    var
      CanShow: Boolean;
      hi: PHintInfo;
    Begin
      CanShow := False;
      hi := PHintInfo(Msg.LParam);
      ShowHintProc(hi.HintStr,CanShow,hi^);
      Msg.Result := Ord(Not CanShow);
    end;
    procedure TLssStringGrid.ShowHintProc(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
    var
      ACol,ARow: Integer;
      HintPos: TRect;
    begin
      MouseToCell(HintInfo.CursorPos.x,HintInfo.CursorPos.y,ACol,ARow);
      if (ACol >= FixedCols) and (ARow >= FixedRows) and
         (ACol < ColCount) and (ARow < RowCount)  then
      begin
        HintStr := Cells[ACol,ARow];
        if Canvas.TextWidth(HintStr) > ColWidths[ACol] then
        begin
          FLastHintPos := Point(ACol,ARow);
          HintPos := CellRect(ACol,ARow);
          HintInfo.HintPos := ClientToScreen(HintPos.TopLeft);
          CanShow := True;
        end;
      end;
    end;procedure TLssStringGrid.MouseMove(Shift: TShiftState; X, Y: Integer);
    var
      ACol,ARow: integer;
    begin
      inherited;
      if (FLastHintPos.x >= 0) and (FLastHintPos.y >= 0) then
      begin
        MouseToCell(x,y,ACol,ARow);
        if (ACol <> FLastHintPos.x) or (ARow <> FLastHintPos.y) then
        begin
          Application.CancelHint;
          FLastHintPos := Point(-1,-1);
        end;
      end;
    end;