Recent

Author Topic: [Solved] TPageControl right click pop-up menu  (Read 839 times)

petevick

  • Sr. Member
  • ****
  • Posts: 337
[Solved] TPageControl right click pop-up menu
« on: January 27, 2023, 10:24:33 am »
In Linux the TPageControl has a pop-up menu when you right click on the tab bar, this is not the PopupMenu property. In Windows this does not work. So initially I created a TPopupMenu for the PopupMenu property, this works fine in both Linux and Windows, BUT, the pop-up menu will pop-up anywhere on the TPageControl, which kinda makes sense, but I would really like it just to pop-up when the tab bar is right clicked.
I Could overlay a TTabControl, but that seems overkill for just a pop-up menu, and more coding.
Any other suggestions would be welcome
« Last Edit: January 27, 2023, 11:37:23 am by petevick »
Pete Vickerstaff
Linux Mint 21.1 Cinnamon, Lazarus 3.2, FPC 3.2.2

balazsszekely

  • Guest
Re: TPageControl right click pop-up menu
« Reply #1 on: January 27, 2023, 10:51:19 am »
In Linux the TPageControl has a pop-up menu when you right click on the tab bar, this is not the PopupMenu property. In Windows this does not work. So initially I created a TPopupMenu for the PopupMenu property, this works fine in both Linux and Windows, BUT, the pop-up menu will pop-up anywhere on the TPageControl, which kinda makes sense, but I would really like it just to pop-up when the tab bar is right clicked.
I Could overlay a TTabControl, but that seems overkill for just a pop-up menu, and more coding.
Any other suggestions would be welcome
Clear PageControl PopupMenu property, then:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.PageControl1MouseUp(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. var
  4.   P: TPoint;
  5. begin
  6.    if Y < PageControl1.Height - TabSheet1.Height - Tabsheet1.BorderWidth then
  7.    begin
  8.      P.X := X;
  9.      P.Y := Y;
  10.      P := PageControl1.ClientToScreen(P);
  11.      PopupMenu1.PopUp(P.X, P.Y);
  12.    end;
  13. end;  

petevick

  • Sr. Member
  • ****
  • Posts: 337
Re: TPageControl right click pop-up menu
« Reply #2 on: January 27, 2023, 11:03:41 am »
Clear PageControl PopupMenu property, then:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.PageControl1MouseUp(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. var
  4.   P: TPoint;
  5. begin
  6.    if Y < PageControl1.Height - TabSheet1.Height - Tabsheet1.BorderWidth then
  7.    begin
  8.      P.X := X;
  9.      P.Y := Y;
  10.      P := PageControl1.ClientToScreen(P);
  11.      PopupMenu1.PopUp(P.X, P.Y);
  12.    end;
  13. end;  
Good grief GetMem, what a brilliantly simple solution.  8-) 8-) 8-) Thank you very much indeed  ;) ;)
Pete Vickerstaff
Linux Mint 21.1 Cinnamon, Lazarus 3.2, FPC 3.2.2

petevick

  • Sr. Member
  • ****
  • Posts: 337
Re: TPageControl right click pop-up menu
« Reply #3 on: January 27, 2023, 11:17:32 am »
Actually, the pop-up menu displays when you click on the tabs as well as right click this also fires the mouseup event, and unfortunatly there is no right mouse click event  :(

....so I use the Shift to check for right click  :-\
« Last Edit: January 27, 2023, 11:21:01 am by petevick »
Pete Vickerstaff
Linux Mint 21.1 Cinnamon, Lazarus 3.2, FPC 3.2.2

petevick

  • Sr. Member
  • ****
  • Posts: 337
Re: TPageControl right click pop-up menu
« Reply #4 on: January 27, 2023, 11:29:07 am »
....or even Button  %)
Pete Vickerstaff
Linux Mint 21.1 Cinnamon, Lazarus 3.2, FPC 3.2.2

balazsszekely

  • Guest
Re: TPageControl right click pop-up menu
« Reply #5 on: January 27, 2023, 11:34:05 am »
Actually, the pop-up menu displays when you click on the tabs as well as right click this also fires the mouseup event, and unfortunatly there is no right mouse click event  :(

....so I use the Shift to check for right click  :-\
I'm not following you. Can you make a screenshot?

PS: Did you clear PageControl1.PopupMenu?

petevick

  • Sr. Member
  • ****
  • Posts: 337
Re: TPageControl right click pop-up menu
« Reply #6 on: January 27, 2023, 11:37:01 am »
I'm not following you. Can you make a screenshot?

PS: Did you clear PageControl1.PopupMenu?
Yes I cleared that. The code wasn't testing for the right mouse button being pressed, so with a slight tweek, it now does.....

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PageControl1MouseUp(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. var
  4.   P: TPoint;
  5. begin
  6.    if Y < PageControl1.Height - TabSheet1.Height - Tabsheet1.BorderWidth then
  7.    begin
  8.      P.X := X;
  9.      P.Y := Y;
  10.      P := PageControl1.ClientToScreen(P);
  11.      if Button = mbRight then TabNames.PopUp(P.X, P.Y);
  12.    end;
  13. end;
Pete Vickerstaff
Linux Mint 21.1 Cinnamon, Lazarus 3.2, FPC 3.2.2

balazsszekely

  • Guest
Re: [Solved] TPageControl right click pop-up menu
« Reply #7 on: January 27, 2023, 11:44:44 am »
@petevick
Quote
Yes I cleared that. The code wasn't testing for the right mouse button being pressed, so with a slight tweek, it now does.....

Ok. Now I see what you meant. You can move Button = mbRight to the first line, so if the condition is not met the code will exit immediately.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.PageControl1MouseUp(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. var
  4.   P: TPoint;
  5. begin
  6.   if (Button = mbRight) and (Y < PageControl1.Height - TabSheet1.Height - Tabsheet1.BorderWidth) then
  7.   begin
  8.     P.X := X;
  9.     P.Y := Y;
  10.     P := PageControl1.ClientToScreen(P);
  11.     PopupMenu1.PopUp(P.X, P.Y);
  12.   end;
  13. end;  

petevick

  • Sr. Member
  • ****
  • Posts: 337
Re: [Solved] TPageControl right click pop-up menu
« Reply #8 on: January 27, 2023, 11:48:24 am »
Ok. Now I see what you meant. You can move Button = mbRight to the first line, so if the condition is not met the code will exit immediately.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.PageControl1MouseUp(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. var
  4.   P: TPoint;
  5. begin
  6.   if (Button = mbRight) and (Y < PageControl1.Height - TabSheet1.Height - Tabsheet1.BorderWidth) then
  7.   begin
  8.     P.X := X;
  9.     P.Y := Y;
  10.     P := PageControl1.ClientToScreen(P);
  11.     PopupMenu1.PopUp(P.X, P.Y);
  12.   end;
  13. end;  

That's even better, thanks again for your help GetMem  ;)
Pete Vickerstaff
Linux Mint 21.1 Cinnamon, Lazarus 3.2, FPC 3.2.2

balazsszekely

  • Guest
Re: [Solved] TPageControl right click pop-up menu
« Reply #9 on: January 27, 2023, 12:02:49 pm »
@petevick
Quote
That's even better, thanks again for your help GetMem  ;)
You're more then welcome!

 

TinyPortal © 2005-2018