Recent

Author Topic: TPageControl and TTabsheet  (Read 5115 times)

fargodwe

  • Newbie
  • Posts: 1
TPageControl and TTabsheet
« on: June 09, 2019, 02:31:55 pm »
I'm just beginning and am trying to set up a form with a tpagecontrol and ttabsheet(s).  I have a few questions I hope someone can answer:

- Is there a way to change the background color of  the tpagecontrol?

- Is there a way to change the background color of a ttabsheet caption?

- Is there a way to create a small separation between the tabs?  Right now they just sort of run together and there really isn't much in the way of a border around each tab (the part where the caption shows)?

I am going to have a lot of questions going forward.  The wiki doesn't show anything but a blank page.  Would like to find something that details each control and possible ways to use them.

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TPageControl and TTabsheet
« Reply #1 on: June 09, 2019, 02:45:31 pm »

background of tpagecontrol: pagecontrol.color := #333333;

color of a ttabsheet caption : play around with the settings

create a small separation between the tabs : again play around with the settings or just add extra spaces behind the caption

I am going to have a lot of questions going forward.  The wiki doesn't show anything but a blank page.  Would like to find something that details each control and possible ways to use them. -=> you can always ask here


You can even do a search on this forum and see if the topic has already been solved or not.
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TPageControl and TTabsheet
« Reply #2 on: June 09, 2019, 02:47:39 pm »
By default the LCL uses native widgets to draw comctrls controls. Depending on your platform and chosen widgetset that may impose restictions on which properties are customisable.
Most widgetsets prevent changing tabcontrol colours to differ from those set by the user's theme.
Micro-management of control properties such as inter-tab spacing would require use of custom-drawn controls, rather than the standard ones the LCL provides.
The wiki is undergoing maintenance currently, but will be up and running in due course.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TPageControl and TTabsheet
« Reply #3 on: June 09, 2019, 03:16:02 pm »
To sum it all up, this tiny bit of code:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ColorizePageCtrl;
  2. begin
  3.   { Change PageControl background and tabs }
  4.   PageControl1.Color := clDkGray;
  5.   PageControl1.Font.Color := clYellow;
  6.   { Change TabSheet color }
  7.   TabSheet1.Color := $00eeff;
  8.   { Don't let controls in the page inherit that "clYellow"}
  9.   TabSheet1.ParentFont := False;
  10. end;

produces the results seen in the attached image. :)

But, as howardpc says, YMMV
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

nouzi

  • Sr. Member
  • ****
  • Posts: 296
Re: TPageControl and TTabsheet
« Reply #4 on: June 09, 2019, 04:07:21 pm »

howto show TabSheet on Right
« Last Edit: June 09, 2019, 04:50:48 pm by nouzi »
My English is  bad
Lazarus last version free pascal last version
Lazarus trunk  free pascal trunk 
System : Linux mint  64bit  Windows 7 64bit

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: TPageControl and TTabsheet
« Reply #5 on: June 09, 2019, 05:59:49 pm »
In windows you don't have much control over the colors. The page control is a windows interface
and it wants the color as is...

There are CustomDrawn controls that allow you to color the tabs and such but that control
has not been updated for a while and it lacks some functionalities .

 You can experiment with TNoteBook and TTabControl in conjunction to get what you want.
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TPageControl and TTabsheet
« Reply #6 on: June 10, 2019, 01:54:22 am »
howto show TabSheet on Right

If you mean the tabs, set PageControl.TabPosition to tpRight either in the object inspector or by code. Other possible values are: tpTop, tpBottom and tpLeft
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

nouzi

  • Sr. Member
  • ****
  • Posts: 296
Re: TPageControl and TTabsheet
« Reply #7 on: June 10, 2019, 12:50:22 pm »
howto show TabSheet on Right

If you mean the tabs, set PageControl.TabPosition to tpRight either in the object inspector or by code. Other possible values are: tpTop, tpBottom and tpLeft
Yes, I know that, thanks lucamar . I mean this
My English is  bad
Lazarus last version free pascal last version
Lazarus trunk  free pascal trunk 
System : Linux mint  64bit  Windows 7 64bit

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TPageControl and TTabsheet
« Reply #8 on: June 10, 2019, 03:10:47 pm »
Oh, OK. Hmm... I don't know if you can do that easily ... let me test a few things. I'll be back.

Later: Easier than I thought. Just set the PageControl's BiDiMode property to bdRightToLeft.

But note that this may have other consequences, so take care. That said, a quick test worked all right here, see attached image.

Also, slightly modified code to cope with more than one tab:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PGColorize;
  2. var
  3.   i: Integer;
  4. begin
  5.   { Change PageControl background and tabs }
  6.   PageControl1.Color := clDkGray;
  7.   PageControl1.Font.Color := clYellow;
  8.   { Change TabSheets color
  9.     Note: You need to do this also for any TabSheet you add in code }
  10.   for i := 0 to PageControl1.PageCount-1 do begin
  11.     { Don't let inner controls inherit that "clYellow"}
  12.     PageControl1.Pages[i].ParentFont := False;
  13.     { TabSheet's backgnd to a "nice" orangey color :) }
  14.     PageControl1.Pages[i].Color := $00eeff;
  15.   end;
  16. end;
« Last Edit: June 10, 2019, 03:54:54 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

nouzi

  • Sr. Member
  • ****
  • Posts: 296
Re: TPageControl and TTabsheet
« Reply #9 on: June 10, 2019, 04:15:33 pm »
ok lucamar thank
you can upload example plz
My English is  bad
Lazarus last version free pascal last version
Lazarus trunk  free pascal trunk 
System : Linux mint  64bit  Windows 7 64bit

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TPageControl and TTabsheet
« Reply #10 on: June 10, 2019, 04:43:16 pm »
There is not much to it, just basically that procedure called from the form's OnCreate handler; but OK, here it is.

ETA: Replaced. Forgot to add the source headers :-[
« Last Edit: June 10, 2019, 05:04:26 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

nouzi

  • Sr. Member
  • ****
  • Posts: 296
Re: TPageControl and TTabsheet
« Reply #11 on: June 10, 2019, 05:30:35 pm »
There is not much to it, just basically that procedure called from the form's OnCreate handler; but OK, here it is.

ETA: Replaced. Forgot to add the source headers :-[
very thank  Again @lucamar
My English is  bad
Lazarus last version free pascal last version
Lazarus trunk  free pascal trunk 
System : Linux mint  64bit  Windows 7 64bit

nouzi

  • Sr. Member
  • ****
  • Posts: 296
Re: TPageControl and TTabsheet
« Reply #12 on: June 10, 2019, 05:37:45 pm »
There is not much to it, just basically that procedure called from the form's OnCreate handler; but OK, here it is.

ETA: Replaced. Forgot to add the source headers :-[
very thank  Again @lucamar
@lucamar
not  show TabSheet on Right
My English is  bad
Lazarus last version free pascal last version
Lazarus trunk  free pascal trunk 
System : Linux mint  64bit  Windows 7 64bit

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TPageControl and TTabsheet
« Reply #13 on: June 10, 2019, 06:17:48 pm »
You're on Windows, right? It may have something to do. Let me check ...
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TPageControl and TTabsheet
« Reply #14 on: June 10, 2019, 08:42:19 pm »
I'm back!

As suspected, things on Windows work ... otherwise. :)

Not only changing colors doesn't work but setting BidiMode to bdRightToLeft affects only the text in the captions. And the secondary effects I hinted to above show in all their splendor.

This last is easy to solve simply by resetting the BidiMode of the TabSheets themselves to bdLeftToRight. The former, unfortunately, doesn't  lend itself to easy measures.

Anyway, find attached a couple of images of the tests on Windows 7 and here is the revised code, FWIW:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PGColorize;
  2. var
  3.   i: Integer;
  4. begin
  5.   { Change PageControl background and tabs }
  6.   PageControl1.Color := clDkGray;
  7.   PageControl1.Font.Color := clYellow;
  8.   { Change TabSheets color }
  9.   for i := 0 to PageControl1.PageCount-1 do begin
  10.     PageControl1.Pages[i].ParentFont := False;
  11.     PageControl1.Pages[i].Color := $00eeff;
  12.     { Solve the problems caused by setting
  13.       PageControl1.BidiMode = bdRightToLeft }
  14.     if PageControl1.BiDiMode <> bdLeftToRight then
  15.       PageControl1.Pages[i].BiDiMode := bdLeftToRight;
  16.   end;
  17. end;
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018