Recent

Author Topic: Best way to handle double click on TTabControl?  (Read 4558 times)

CM630

  • Hero Member
  • *****
  • Posts: 1091
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Best way to handle double click on TTabControl?
« on: October 24, 2017, 07:30:37 am »
It occurs that TTabControl has no DoubleClick event. Pretty odd, since double-click is a standard way to close tabs.
So I wonder which is the best way to handle double click?
Should I use OnMouseDown with a timer? IMHO this would be a wrong solution, since speed of double speed click is adjustable trough the OS settings.
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Best way to handle double click on TTabControl?
« Reply #1 on: October 24, 2017, 10:05:27 am »
It occurs that TTabControl has no DoubleClick event. Pretty odd, since double-click is a standard way to close tabs.
Since when? Which application/OS gives the ability to close a tab with a double click? In my experience double click does a number of different things from renaming the tab to detaching it from the page control and making it float. Personally I always use the middle mouse button up event to close a tab.
So I wonder which is the best way to handle double click?
Should I use OnMouseDown with a timer? IMHO this would be a wrong solution, since speed of double speed click is adjustable trough the OS settings.

The on double click event is already implemented in the Tcontrol class (parent of ttabcontrol) you just need to surface it and attach to it your handler just add
Code: Pascal  [Select][+][-]
  1.    TTabControl = class(ComCtrls.TTabControl)
  2.      property OnDblClick;
  3.    end;
  4.  
before your form's declaration in the same unit and attach to your existing tab controls an event handler from code no designer support for this. see if that works for you.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

CM630

  • Hero Member
  • *****
  • Posts: 1091
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Best way to handle double click on TTabControl?
« Reply #2 on: October 24, 2017, 11:04:34 am »
Since when?...
Indeed, it occurs that I am so much used to AkelPad...

I did the code before, but it does not fire:
Code: Pascal  [Select][+][-]
  1. uses
  2. ...
  3.  
  4.  
  5. type
  6.  
  7.  
  8. TTabControl = class(ComCtrls.TTabControl)
  9.    property OnDblClick;
  10. end;          
  11.  
  12.  
  13. ....
  14.  
  15.  
  16. TfrmMain = class(TForm)
  17. ...
  18.     procedure EventTabDblClick(Sender: TObject);
  19. ...    
  20. end;
  21.  
  22.  
  23.  
  24.  
  25. procedure TfrmMain.EventTabDblClick(Sender: TObject);
  26. begin
  27.   msgbox ('afsdsafds');
  28. end;
  29.  
  30.  
  31.  
  32.  
  33. procedure TfrmMain.FormCreate(Sender: TObject);
  34. begin
  35. ...
  36.    tbcMain.OnDblClick:=@EventTabDblClick;
  37. ...
  38. end;

Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Best way to handle double click on TTabControl?
« Reply #3 on: October 24, 2017, 11:21:23 am »
I did the code before, but it does not fire:
I'll take a closer look later tonight to see why it does not fire.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

balazsszekely

  • Guest
Re: Best way to handle double click on TTabControl?
« Reply #4 on: October 24, 2017, 11:22:25 am »
You must set ControlStyle, like this:
Code: Pascal  [Select][+][-]
  1.   TTabControl = class(ComCtrls.TTabControl)
  2.   public
  3.     property OnDblClick;
  4.     constructor Create(TheOwner: TComponent); override;
  5.   end;
  6.  
  7.   TForm1 = class(TForm)
  8.     TabControl1: TTabControl;
  9.     procedure FormCreate(Sender: TObject);
  10.   private
  11.     procedure EventTabDblClick(Sender: TObject);
  12.   public
  13.  
  14.   end;
  15.  
  16. var
  17.   Form1: TForm1;
  18.  
  19. implementation
  20.  
  21. {$R *.lfm}
  22.  
  23. constructor TTabControl.Create(TheOwner: TComponent);
  24. begin
  25.   inherited Create(TheOwner);
  26.   ControlStyle := ControlStyle + [csClickEvents, csDoubleClicks];
  27. end;
  28.  
  29. procedure TForm1.FormCreate(Sender: TObject);
  30. begin
  31.   TabControl1.OnDblClick := @EventTabDblClick;
  32. end;
  33.  
  34. procedure TForm1.EventTabDblClick(Sender: TObject);
  35. begin
  36.   ShowMessage('afsdsafds');
  37. end;

CM630

  • Hero Member
  • *****
  • Posts: 1091
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Best way to handle double click on TTabControl?
« Reply #5 on: October 24, 2017, 11:52:12 am »
Thanks,
GetMem's solution almost works or precisely: It works if I dobleclick on the big rectangle (TTabControls container/area or whatever it is called), but it does not work if I click on the tab itself. :-[
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

CM630

  • Hero Member
  • *****
  • Posts: 1091
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Best way to handle double click on TTabControl?
« Reply #6 on: October 25, 2017, 08:53:06 am »
Probably I should better search for an alternative, which has close buttons in the tabs.
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Best way to handle double click on TTabControl?
« Reply #7 on: October 25, 2017, 09:29:09 am »
Probably I should better search for an alternative, which has close buttons in the tabs.
oops sorry I forgot about it. well I added an alert on my phone for when I get back from work. In the mean time you can use attabs it has close buttons and already supports double clicks etc if you want a pagecontrol experience instead drop me a pm I'll see what I can do.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

CM630

  • Hero Member
  • *****
  • Posts: 1091
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Best way to handle double click on TTabControl?
« Reply #8 on: October 25, 2017, 04:13:22 pm »
Thanks @Taazz but please do not bother. I combined an EyeCandy tab control with a TPanel, I think it would do for me. ;D
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

 

TinyPortal © 2005-2018