Recent

Author Topic: Floating informational box when you put mouse over string grid cell  (Read 4067 times)

vonskie

  • Full Member
  • ***
  • Posts: 186
How do you do this?


howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Floating informational box when you put mouse over string grid cell
« Reply #1 on: March 10, 2017, 11:53:06 pm »
You can adapt this sort of code to your needs:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Forms, Controls, Grids, sysutils;
  9.  
  10. type
  11.  
  12.   TForm1 = class(TForm)
  13.     StringGrid1: TStringGrid;
  14.     procedure FormCreate(Sender: TObject);
  15.   private
  16.     procedure GridShowHint(Sender: TObject; HintInfo: PHintInfo);
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.lfm}
  25.  
  26. procedure TForm1.FormCreate(Sender: TObject);
  27. begin
  28.   StringGrid1.ShowHint:=True;
  29.   StringGrid1.OnShowHint:=@GridShowHint;
  30. end;
  31.  
  32. procedure TForm1.GridShowHint(Sender: TObject; HintInfo: PHintInfo);
  33. var
  34.   col: integer = -1;
  35.   row: integer = -1;
  36.   grid: TStringGrid absolute Sender;
  37. begin
  38.   grid.MouseToCell(HintInfo^.CursorPos.X, HintInfo^.CursorPos.Y, col, row);
  39.   HintInfo^.HintStr:=Format('Hint for cell(%d,%d)',[col, row]);
  40.   HintInfo^.HideTimeout:=5000; // long-lasting hint
  41. end;
  42.  
  43. end.

mirce.vladimirov

  • Sr. Member
  • ****
  • Posts: 269
Re: Floating informational box when you put mouse over string grid cell
« Reply #2 on: March 10, 2017, 11:55:19 pm »
It's called Hint, but I dont know how to display it on a specific location on the screen.
Hint is available for all GUI controls and if set then it is displayed when you place the mouse pointer over the control.
You should Set "ShowHint" to true in the Object Inspector, and set the "Hint" also in Object Inspector.
You can also change these values during runtime :
Code: Pascal  [Select][+][-]
  1. dbgrid1.showhint:=true;
  2. dbgrid1.hint:='This is the hint of the dbgrid';
This would display the same hint no matter where the mouse is placed over the DBgrid.
I don't know how to display a different hint for each cell in a grid.

Graeme

  • Hero Member
  • *****
  • Posts: 1518
    • Graeme on the web
Re: Floating informational box when you put mouse over string grid cell
« Reply #3 on: March 13, 2017, 01:01:57 pm »
Sometimes a hint windows is not a good fit for a "information window". What we have done previously with a window containing a StringGrid, is create a hidden Panel (or Bevel), then place all our needed components into that (images, Label, Memo etc). Then as the user moves the mouse over the cells in the grid, we populate the information window with the needed information, then made the hidden panel visible, bumped its Z-order (to always be on top) and position it near the StringGrid cell in question (optional). When the mouse left the StringGrid, we hid the panel again.

This was in the days of Delphi 5-7, and it worked very well. I believe it will still work well for your needs today.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

 

TinyPortal © 2005-2018