Recent

Author Topic: How do I enable switching between tabs via <ctrl>-<tab> and <ctrl>-<shift>-<tab>  (Read 2665 times)

OLLI_S

  • Full Member
  • ***
  • Posts: 111
Theorically it's just for that but IIRC it's one of those (so many!) things that depend on the widgetset, the support in the WM and the phase of the moon. One can but try it in one's program and be aware of the possible workarounds in case it doesn't work.

Indeed, I forgot the phase of the moon.
 %)

I am using the solution from taazz:

go simple use actions.
1) add an actionlist in your form
2) add two new actions
3) named appropriatly eg actTabforward and actTabBack.
4) write on the onexecute hcode like
Code: Pascal  [Select]
  1. procedure TForm1.ActTabForwardExecute(Sender :TObject);
  2. begin
  3.   if PageControl1.TabIndex = 0 then PageControl1.TabIndex = PageControl1.PageCount -1
  4.   else PageControl1.TabIndex := PageControl1.TabIndex - 1;
  5. end;
  6.  
  7. procedure TForm1.ActTabBackExecute(Sender :TObject);
  8. begin
  9.   if PageControl1.TabIndex = PageControl1.PageCount -1 then PageControl1.TabIndex := 0
  10.   else PageControl1.TabIndex := PageControl1.TabIndex+1;
  11. end;
  12.  
5) make sure the actions have the appropariate shortcuts ctrl+tab and shift+ctrl+tab.

done.


lucamar

  • Hero Member
  • *****
  • Posts: 1299
Better than manipulating TabIndex, use SelectNextPage(), as zoltanleo said. Way cleaner! ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 1.8.4 & 2.0.2 w/FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

Yukiko

  • New member
  • *
  • Posts: 30
In my case, Taazz's solution was better because I have a hidden page that I use to display various debugging info. I unhide it for testing and rehide it for the release. I just skip to the first page when the last normally visible page is active. However, in normal cases, I can see where your solution, zoltanleo, would be more optimal.

OLLI_S

  • Full Member
  • ***
  • Posts: 111
I also have a "hidden" tab for debug information.
But I allow the user to make it visible (so when any problem occurs then I can tell the user to send me the the debug information).
So I check if the tab is shown or not and then set the TabIndex to the correct tab.
« Last Edit: February 28, 2019, 10:31:08 am by OLLI_S »

zoltanleo

  • Full Member
  • ***
  • Posts: 165
@Yukiko
@OLLI_S

There is an overloaded method SelectNextPage(GoForward: Boolean; CheckTabVisible: Boolean) that call inside FindNextPage method
Code: Pascal  [Select]
  1. procedure TPageControl.SelectNextPage(GoForward: Boolean;
  2.   CheckTabVisible: Boolean);
  3. var
  4.   NextPage: TTabSheet;
  5. begin
  6.   NextPage:=FindNextPage(ActivePage,GoForward,CheckTabVisible);
  7.   if NextPage<>nil then ActivePage:=NextPage;
  8. end;

2nd parameter CheckTabVisible: Boolean takes into account the invisible tabs. For more see here: https://lazarus-ccr.sourceforge.io/docs/lcl/comctrls/tpagecontrol.selectnextpage.html
Win7 Ultim x64/Deb 9.7 i386 GTK2:
Lazarus 2.1(r.60225); FPC 3.3.1 (r.41075),
IBX by -Rik-; FB 3.0.4

Sorry for my bad English, I'm using translator ;)

OLLI_S

  • Full Member
  • ***
  • Posts: 111
There is an overloaded method SelectNextPage(GoForward: Boolean; CheckTabVisible: Boolean) that call inside FindNextPage method
2nd parameter CheckTabVisible: Boolean takes into account the invisible tabs. For more see here: https://lazarus-ccr.sourceforge.io/docs/lcl/comctrls/tpagecontrol.selectnextpage.html

Hello zoltanleo,

thank you very much for your posting!

Your solution is just one line (here I write both lines, for switching to the next and previous page):
Code: Pascal  [Select]
  1. pgePages.SelectNextPage(True, True);  // Go to next visible page
  2. pgePages.SelectNextPage(False, True); // Go to previous visible page

My current solution was 5 lines for each  direction, now I just have one line.
So thank you!

OLLI
« Last Edit: March 01, 2019, 12:06:12 pm by OLLI_S »