Recent

Author Topic: TPageControl and TTabsheet  (Read 817 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: 661
  • ..... A day not Laughed is a day not Lived !!
    • 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 2.0.2 / FPC 3.0.4
Lazarus Trunc / FPC 3.0.4
Mac OS X Mojave

howardpc

  • Hero Member
  • *****
  • Posts: 3011
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: 1545
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 1.8.4 & 2.0.2 w/FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

nouzi

  • Full Member
  • ***
  • Posts: 105
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 2.0 free pascal 3.0.4
Lazarus trunk  free pascal trunk 
System : windows 7 64bit

jamie

  • Hero Member
  • *****
  • Posts: 1548
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.

lucamar

  • Hero Member
  • *****
  • Posts: 1545
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 1.8.4 & 2.0.2 w/FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

nouzi

  • Full Member
  • ***
  • Posts: 105
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 2.0 free pascal 3.0.4
Lazarus trunk  free pascal trunk 
System : windows 7 64bit

lucamar

  • Hero Member
  • *****
  • Posts: 1545
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 1.8.4 & 2.0.2 w/FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

nouzi

  • Full Member
  • ***
  • Posts: 105
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 2.0 free pascal 3.0.4
Lazarus trunk  free pascal trunk 
System : windows 7 64bit

lucamar

  • Hero Member
  • *****
  • Posts: 1545
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 1.8.4 & 2.0.2 w/FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

nouzi

  • Full Member
  • ***
  • Posts: 105
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 2.0 free pascal 3.0.4
Lazarus trunk  free pascal trunk 
System : windows 7 64bit

nouzi

  • Full Member
  • ***
  • Posts: 105
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 2.0 free pascal 3.0.4
Lazarus trunk  free pascal trunk 
System : windows 7 64bit

lucamar

  • Hero Member
  • *****
  • Posts: 1545
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 1.8.4 & 2.0.2 w/FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

lucamar

  • Hero Member
  • *****
  • Posts: 1545
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 1.8.4 & 2.0.2 w/FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.