Recent

Author Topic: [Solved] TStringGrid displaying a popup menu on a cell  (Read 213 times)

jcmontherock

  • Sr. Member
  • ****
  • Posts: 356
[Solved] TStringGrid displaying a popup menu on a cell
« on: May 10, 2026, 04:39:51 pm »
I have the following code to display a popup menu when clicking with the right mouse button on a cell:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. var
  4.   pTopLeft: TPoint;
  5. begin
  6.   if (Button = TMouseButton.mbRight)  And (Shift = [ssRight]) then begin
  7.       pTopLeft := ClientToScreen(Point(X, Y));
  8.       PopupMenu2.Popup(pTopLeft.X, pTopLeft.Y+100);
  9.   end;
  10. end;
It's work perfectly. The X param is OK,  but I do not understand why I should add 100 pixels(?) to the point Y to be on the mouse arrow ?
« Last Edit: May 11, 2026, 11:31:46 am by jcmontherock »
Windows 11 UTF8-64 - Lazarus 4.6-64 - FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 7776
Re: TStringGrid displaying a popup menu on a cell
« Reply #1 on: May 10, 2026, 05:18:04 pm »
You would think that work and you are correct on that assumption.

what Widget are you on?

 In any case, try using the Mouse.CursorPos instead, that is the screen X,Y

 P.S.
   Your Grid could be scrolled up a little when you do that.
Jamie




« Last Edit: May 10, 2026, 05:20:20 pm by jamie »
The only true wisdom is knowing you know nothing

jcmontherock

  • Sr. Member
  • ****
  • Posts: 356
Re: TStringGrid displaying a popup menu on a cell
« Reply #2 on: May 11, 2026, 11:30:47 am »
Thanks: Mouse.cursor works better and is more simpler to use.
« Last Edit: May 11, 2026, 11:45:22 am by jcmontherock »
Windows 11 UTF8-64 - Lazarus 4.6-64 - FPC 3.2.2

 

TinyPortal © 2005-2018