?
Solved

Tooltip for stringgrids cells

Posted on 2008-10-22
2
Medium Priority
?
741 Views
Last Modified: 2013-11-23
Hello,

I'm in the need of a code that can:
show a tooltip over a stringgrid (it should be shown just under the cell that the mouse pointer hovers). it should be shown about 0,5sec after the mouse enters the cell, and only if the text in the cell is too long to fit in the cell (i use drawtext in the ondrawcell event to paint the text inside the cells). and it should be shown as long as the mouse cursor is in the cell (even if it's moved, but inside the cell).

Best regards
szafran81
0
Comment
Question by:szafran81
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
SteveBay earned 2000 total points
ID: 22778847
Place a TStringGrid on a form and try this code. I think it's very close to what you are asking for. With thanks to meikl
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20737679.html
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls;
 
Type MyGrid = class(TStringGrid);
 
type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Label1: TLabel;
    procedure FormShow(Sender: TObject);
    procedure StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
     LastGridCoord : TGridCoord;
     procedure DisplayHint(Sender: TObject);
  public
     procedure OnShowHint(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.DisplayHint(Sender: TObject);
begin
end;
 
procedure TForm1.FormShow(Sender: TObject);
begin
     Application.OnShowHint := OnShowHint;
end;
 
procedure TForm1.OnShowHint(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
var GridCoord : TGridCoord;
     Grid : TStringGrid;
begin
     if (HintInfo.HintControl is TStringGrid) then
          begin
          Grid := TStringGrid(HintInfo.HintControl);
          GridCoord := Grid.MouseCoord(HintInfo.CursorPos.x,HintInfo.CursorPos.y);
          HintStr := Grid.Cells[GridCoord.X, gridCoord.Y];
          if Grid.Canvas.TextWidth(HintStr) > Grid.CellRect(GridCoord.X, gridCoord.Y).Right - Grid.CellRect(GridCoord.X, gridCoord.Y).Left then
               begin
               HintInfo.HintPos.X := Self.ClientOrigin.X + Grid.Left + Grid.CellRect(GridCoord.X, gridCoord.Y).Left;
               HintInfo.HintPos.Y :=  Self.ClientOrigin.Y + Grid.Top  +
                         Grid.CellRect(GridCoord.X, gridCoord.Y).Bottom;
               HintInfo.ReshowTimeout := 500;
               end
          else
               CanShow := False;
          end;
end;
 
procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var Grid : TStringGrid;
begin
     if Sender is TStringGrid then
          begin
          Grid := TStringGrid(Sender);
          if (LastGridCoord.X <> Grid.MouseCoord(X,Y).X ) and
              (LastGridCoord.Y <> Grid.MouseCoord(X,Y).Y ) Then
               begin
               Application.HideHint;
               LastGridCoord := TStringGrid(Sender).MouseCoord(X,Y);
               end;
          end;
end;
 
end.

Open in new window

0
 

Author Comment

by:szafran81
ID: 22791588
hmm... i haven't received any emails that you added a comment here... just came to close the Q, since i've just finished writing my own code for this (but based on a timer and a statictext as tooltip - works great)... as i can see the code is very similar... so i can accept your solution (to bad i haven't seen it earlier).
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month8 days, 2 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question