Recent

Author Topic: [Solved] - Buttons in TTabsheet and TPageControl  (Read 2597 times)

zxandris

  • Full Member
  • ***
  • Posts: 154
[Solved] - Buttons in TTabsheet and TPageControl
« on: October 16, 2023, 08:00:34 am »
Okay I've noticed that the PageControl options say you can have close buttons on the tabs, but I've set this and they're not showing up.  I'm assuming there is more work to be done, and would like to please ask what actually needs to happen to get those close buttons to show up on the tab, and presumably setup an event to catch the click?

Any help would be appreciated, I can't so much offer a code example here, as to me it seems like it's a simple property set, but I'm going out on a limb and saying it's not that easy since that's not working for me.

« Last Edit: October 20, 2023, 09:25:01 am by zxandris »

cdbc

  • Hero Member
  • *****
  • Posts: 2142
    • http://www.cdbc.dk
Re: Buttons in TTabsheet and TPageControl
« Reply #1 on: October 16, 2023, 08:13:53 am »
Hi
1) In the ObjectInspector, choose "PageControl1" -> find the "Options" section
   -> find "ShowCloseButton" and turn it on.
2) In the ObjectInspector, choose the page "Events" -> find "CloseTab"
   -> click the elipsis(...) and create an event-handler for that:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.PageControl1CloseTabClicked(Sender: TObject); { * }
  2. begin
  3.   (Sender as TTabSheet).Free;
  4. end;
  5.  
HTH
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

zxandris

  • Full Member
  • ***
  • Posts: 154
Re: Buttons in TTabsheet and TPageControl
« Reply #2 on: October 16, 2023, 08:15:03 am »
Doh! so all I needed to do was add the event and then the button will actually show?

Handoko

  • Hero Member
  • *****
  • Posts: 5425
  • My goal: build my own game engine using Lazarus
Re: Buttons in TTabsheet and TPageControl
« Reply #3 on: October 16, 2023, 08:30:13 am »
Close button for tabs is working good on Linux. But the buttons won't appear on Windows. It could be widgetset issue, bug or unimplemented feature, I am not sure. If anyone interested, you can submit a bug report.

Luckily there is a workaround for it. I have tested it on Windows, it worked:
https://forum.lazarus.freepascal.org/index.php/topic,52236.msg384585.html#msg384585

cdbc

  • Hero Member
  • *****
  • Posts: 2142
    • http://www.cdbc.dk
Re: Buttons in TTabsheet and TPageControl
« Reply #4 on: October 16, 2023, 08:31:08 am »
Hi
Well, this way works for me in a heartbeat  :D
Btw. if you want a button on your tabsheet to close the tabsheet, you have to use "SendMessage" to do so  8-)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

zxandris

  • Full Member
  • ***
  • Posts: 154
Re: Buttons in TTabsheet and TPageControl
« Reply #5 on: October 16, 2023, 08:33:35 am »
Close button for tabs is working good on Linux. But the buttons won't appear on Windows. It could be widgetset issue, bug or unimplemented feature, I am not sure. If anyone interested, you can submit a bug report.

Luckily there is a workaround for it. I have tested it on Windows, it worked:
https://forum.lazarus.freepascal.org/index.php/topic,52236.msg384585.html#msg384585

Thanks, I'll give that a go :)

Awkward

  • Full Member
  • ***
  • Posts: 146
Re: Buttons in TTabsheet and TPageControl
« Reply #6 on: October 16, 2023, 10:35:22 am »
Close button for tabs is working good on Linux. But the buttons won't appear on Windows. It could be widgetset issue, bug or unimplemented feature, I am not sure.

That is not bug. This is F*king windows issue. MS Windows don't have native "close" buttons there. Another question, why it was not implemented by LCL internally...

zxandris

  • Full Member
  • ***
  • Posts: 154
Re: Buttons in TTabsheet and TPageControl
« Reply #7 on: October 16, 2023, 10:36:59 am »
From a glance at the code I assume I'll have to create this dynamically as it's not set up as a component.  I'm not alien to doing that but I've not done it much yet.  Honestly, I've been programming years but in many ways I would still consider myself a noob.  So tips would be helpful :)

TRon

  • Hero Member
  • *****
  • Posts: 4369
Re: Buttons in TTabsheet and TPageControl
« Reply #8 on: October 16, 2023, 10:45:43 am »
From a glance at the code I assume I'll have to create this dynamically as it's not set up as a component. ... So tips would be helpful :)
I couldn't locate a wiki page on the first page of my search results (bad day for getting the right search-terms it seems  :) ) but found this so q&a and this thread instead. Delphi and Lazarus are practically similar in that regards so the links should be able to get you going ?
Today is tomorrow's yesterday.

zxandris

  • Full Member
  • ***
  • Posts: 154
Re: Buttons in TTabsheet and TPageControl
« Reply #9 on: October 16, 2023, 11:20:11 am »
That helps thanks, luckily it's not alien to me, i was just curious as to the exact details of https://forum.lazarus.freepascal.org/index.php/topic,52236.msg384585.html#msg384585 really.

TRon

  • Hero Member
  • *****
  • Posts: 4369
Re: Buttons in TTabsheet and TPageControl
« Reply #10 on: October 16, 2023, 11:54:40 am »
@zxandris:
As far as I am able to tell form my quick glance over the code in that link there are no new properties or other storage streams introduced which afaik means that you can literally copy the code and drop a tpagecontrol on your form with the designer (note the order in the original source-code which allows to override the original tpagecontrol component with the customized implementation.
Today is tomorrow's yesterday.

zxandris

  • Full Member
  • ***
  • Posts: 154
Re: Buttons in TTabsheet and TPageControl
« Reply #11 on: October 16, 2023, 12:51:49 pm »
That's great I'll experiment a little before I try to insert that into my more production code I think.  I'm essentially trying to implement as close as I can get to a browser like tab control, so I suppose the next question is how do I change the color of the tabs? :).  It sounds simple, but I seriously doubt it is so.  I'm still very inexperienced with that sort of thing and I suspect that some sort of custom control might be required which is definitely beyond anything I've done before.  But I'm keen to get this working for my project.  Any help would be appreciated.

TRon

  • Hero Member
  • *****
  • Posts: 4369
Re: Buttons in TTabsheet and TPageControl
« Reply #12 on: October 16, 2023, 02:14:10 pm »
...trying to implement as close as I can get to a browser like tab control, so I suppose the next question is how do I change the color of the tabs? :).  It sounds simple, but I seriously doubt it is so.  I'm still very inexperienced with that sort of thing and I suspect that some sort of custom control might be required which is definitely beyond anything I've done before.  But I'm keen to get this working for my project.  Any help would be appreciated.
Perhaps not exactly what you are looking for but I was very impressed by all shenanigans from ATTabs. There are more customdrawn controls out there (customdrawn is probably most helpful for your use case because it unties things with the OS widgetset).
Today is tomorrow's yesterday.

d7_2_laz

  • Hero Member
  • *****
  • Posts: 637
Re: Buttons in TTabsheet and TPageControl
« Reply #13 on: October 16, 2023, 02:52:54 pm »
Once being in the same situation, i'd decided for this ATTabs and i'm happy with it due to it's configuration and styling capabilities.
https://forum.lazarus.freepascal.org/index.php/topic,53422.msg395158.html#msg395158
Lazarus 4.0  FPC 3.2.2 Win10 64bit

jamie

  • Hero Member
  • *****
  • Posts: 6892
Re: Buttons in TTabsheet and TPageControl
« Reply #14 on: October 17, 2023, 02:24:38 am »
I subclassed the TpageControl locally and I put combo boxes on the selected tab and normal looking unselected.

The Drop down selects the caption for that tab which also indicates mode of operation for that tab.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018