Lazarus

Free Pascal => Beginners => Topic started by: fargodwe on June 09, 2019, 02:31:55 pm

Title: TPageControl and TTabsheet
Post by: fargodwe 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.
Title: Re: TPageControl and TTabsheet
Post by: madref 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.
Title: Re: TPageControl and TTabsheet
Post by: howardpc 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.
Title: Re: TPageControl and TTabsheet
Post by: lucamar 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
Title: Re: TPageControl and TTabsheet
Post by: nouzi on June 09, 2019, 04:07:21 pm

howto show TabSheet on Right
Title: Re: TPageControl and TTabsheet
Post by: jamie 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.
Title: Re: TPageControl and TTabsheet
Post by: lucamar 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
Title: Re: TPageControl and TTabsheet
Post by: nouzi 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
Title: Re: TPageControl and TTabsheet
Post by: lucamar 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;
Title: Re: TPageControl and TTabsheet
Post by: nouzi on June 10, 2019, 04:15:33 pm
ok lucamar thank
you can upload example plz
Title: Re: TPageControl and TTabsheet
Post by: lucamar 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 :-[
Title: Re: TPageControl and TTabsheet
Post by: nouzi 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
Title: Re: TPageControl and TTabsheet
Post by: nouzi 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
Title: Re: TPageControl and TTabsheet
Post by: lucamar on June 10, 2019, 06:17:48 pm
You're on Windows, right? It may have something to do. Let me check ...
Title: Re: TPageControl and TTabsheet
Post by: lucamar 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;
Title: Re: TPageControl and TTabsheet
Post by: nouzi on June 11, 2019, 11:32:51 am
 thank  for all time lucamar
Yes Henk is a problem in supporting languages ​​from right to left
Also the shellfish is a similar problem in the dbgride when changing the settings from right to left cursor acts opposite the direction of the grid
Are they recommended solutions?
And raise this Ka bug

--------------
Translation by Google
Title: Re: TPageControl and TTabsheet
Post by: lucamar on June 11, 2019, 01:17:10 pm
As Jaime said, the recommended solution for all this is to use custom drawn controls, i.e. controls which don't depend on the default drawing being done by the system.

I don't use them normally so I can't recommend any one set, but there are quite a lot of them. Search the wiki for a few and use whchever takes your fancy.

Beyond that, what I do the few times I need to tweak how some control draws is to add a handler to its OnPaint event. Unfortunately (for your use case) both TPageControl and TTabSheet descends almost directly from TWinControl and the OnPaint event is introduced by TCustomControl, which means they don't have it.

I'm not sure what else I can tell you, except ... just let it draw as it wants! That's what desktop theming is for :)


BTW, completely unrelated but "Google translate" did you a diservice: shellfish? Henk? Ka bug? WTH? :D
Title: Re: TPageControl and TTabsheet
Post by: nouzi on June 11, 2019, 02:25:27 pm
 lucamar this work in delphi
Code: Pascal  [Select]
  1.  procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3. SetWindowLong(PageControl1.Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_ID) or $400000)
  4. end;
  5.  
can not find SetWindowLong in lib lazarus
after cherch im use this inc file
https://lazarus-ccr.sourceforge.io/docs//lcl/lclintf/setwindowlong.html (https://lazarus-ccr.sourceforge.io/docs//lcl/lclintf/setwindowlong.html)
find error
Code: PHP  [Select]
  1. ...
  2. Warning: Duplicate file "wincontrol.inc" in "LCLBase 2.0.2", path="D:\bin_dev\stable\lazarus\lcl\include\wincontrol.inc"
  3. winapih.inc(35,18) Error: Identifier not found "HDC"
  4. winapih.inc(35,18) Error: Identifier not found "HDC"
  5. winapih.inc(38,30) Error: Identifier not found "hwnd"
  6. ...
  7.  

name this Technology Mirror
Title: Re: TPageControl and TTabsheet
Post by: lucamar on June 11, 2019, 04:01:05 pm
SetWindowLong is declared in the unit LCLIntf; you just have to add lclintf to your uses clause.
Title: Re: TPageControl and TTabsheet
Post by: nouzi on June 12, 2019, 10:38:22 am
SetWindowLong is declared in the unit LCLIntf; you just have to add lclintf to your uses clause.
thank lucamar not work
Code: PHP  [Select]
  1.  
  2. Compile Project, Target: D:\bin_dev\stable\projects\project1.exe: Exit code 1, Errors: 4
  3. unit1.pas(48,38) Error: Identifier not found "GWL_EXSTYLE"
  4. unit1.pas(48,73) Error: Identifier not found "GWL_ID"
  5. unit1.pas(49,37) Error: Identifier not found "GWL_EXSTYLE"
  6. unit1.pas(49,72) Error: Identifier not found "GWL_ID"
  7.  
  8.  
Title: Re: TPageControl and TTabsheet
Post by: nouzi on June 12, 2019, 10:43:44 am
solved after change  the unit LCLIntf with windows
Title: Re: TPageControl and TTabsheet
Post by: nouzi on June 12, 2019, 10:56:16 am
 deformation See the attached pictures