Recent

Author Topic: Add images to tabs tabcontrol  (Read 8400 times)

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Add images to tabs tabcontrol
« on: May 02, 2016, 07:34:43 am »
Hi my friends, how can add images to tabs of tabcontrol.  :)

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: Add images to tabs tabcontrol
« Reply #1 on: May 02, 2016, 03:45:30 pm »
some idea  ::)

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Add images to tabs tabcontrol
« Reply #2 on: May 02, 2016, 05:02:11 pm »
Never tried, but I think you may perform the drawing by setting event on TabControl.OnDrawTab.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.TabControl1DrawTab(Control: TCustomTabControl;
  2.   TabIndex: Integer; const Rect: TRect; AActive: Boolean);
  3. begin
  4.   // put your code here
  5. end;

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: Add images to tabs tabcontrol
« Reply #3 on: May 02, 2016, 05:17:44 pm »
Thanks, I added a imagelist with three images (32x32), also linked to the "Images" property of tabcontrol... but nothing  :( :(
(sorry for the grammar, I am using google traslate)

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Add images to tabs tabcontrol
« Reply #4 on: May 02, 2016, 05:24:47 pm »
I think there was a similar question recently, but I tested it again: No, it's not working with TTabControl (at least on Windows), it is working with a TPageControl, though. So, why don't you use this one instead as a workaround? The TabControl has only one page, which is displayed for all tabs. You can do this with TPageControl as well, just move the parent of the controls on the current tabsheet to the newly selected tabsheet in the OnOnChange event. It is very easy if all controls are on a panel - see attached project.

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: Add images to tabs tabcontrol
« Reply #5 on: May 02, 2016, 05:37:14 pm »
It is very good idea my friend  :), then tabcontrol can not put images  :(

tk

  • Sr. Member
  • ****
  • Posts: 361
Re: Add images to tabs tabcontrol
« Reply #6 on: May 02, 2016, 09:33:01 pm »
We use now our own page control to support images in tabs and a close button among other things - is part of my Kcontrols http://tkweb.eu/en/delphicomp/.
Maybe you could use only the tab panel if you need only tabs. Not yet fully tested under Lazarus though, but the current repo download should work...

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: Add images to tabs tabcontrol
« Reply #7 on: May 02, 2016, 10:10:48 pm »
thanks my friends, I found this tutorial:
http://stackoverflow.com/questions/8290698/how-i-can-set-the-imageindex-for-a-tab-of-an-ttabset-component

Code: Pascal  [Select][+][-]
  1. // You must use the TTabSet.OnGetImageIndex event to assing a particular imageindex to a tab.
  2. // check this sample
  3.  
  4. procedure TForm1.TabSet1GetImageIndex(Sender: TObject; TabIndex: Integer;
  5.   var ImageIndex: Integer);
  6. begin
  7.  Case TabIndex of
  8.   0: ImageIndex:=0;
  9.   1: ImageIndex:=1;
  10.   2  ImageIndex:=2;
  11.  end;
  12. end;

but nothing happens  :( :( :(

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Add images to tabs tabcontrol
« Reply #8 on: May 02, 2016, 10:28:17 pm »
Yes, this is for Delphi. Lazarus has an issue with images in TTabControl.

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: Add images to tabs tabcontrol
« Reply #9 on: May 03, 2016, 01:07:31 am »
Friend "wp" thanks very much for the example, following your example I did this:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   if PageControl1.TabIndex=0 then Button1.Caption:='tab0';   // VERIFICAR la primera pestaña al inicio
  4. end;
  5.  
  6. procedure TForm1.PageControl1Change(Sender: TObject);
  7. begin
  8.     Panel1.Parent := PageControl1.Pages[PageControl1.ActivePageIndex];
  9.  
  10.     case PageControl1.TabIndex of
  11.     0: begin
  12.     Button1.Caption:='tab0';
  13.     end;
  14.     1: begin
  15.     Button1.Caption:='tab1';
  16.     end;
  17.     2: begin
  18.     Button1.Caption:='tab2';
  19.     end;
  20.     end;
  21. end;


I link icons on the property "imageindex" of each TabSheet. (0, 1, 2)
for now works fine!!  :D :D  :D

 

TinyPortal © 2005-2018