Forum > LCL
Disable theming for a TPageControl
Bart:
Hi,
On Windows (10) a TTabSheet of a TPageControl looks hideous (its white on my default (not dark) theme).
I have one application where I diable theming for a specific TPageControl using this code in the form's OnCreate
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- UxTheme.SetWindowTheme(NoteBook.Handle, nil, ''); //NoteBook is a TPageControlThis works like I want it to be: the TTabSheets have the same color as the form they reside on (standard clForm color).
Now: in another application I wanted to do the same:
I have a NoteBook: TPageControl on a Form.
I run the same code ase above in the form's OnCreate.
But to no effect: the TTabSheet remains white (not clForm).
I tried setting the TTabSheet.Color to clForm: to no avail.
I tried to disable theming on the TTabSheet, but the effect was that no text was shown anywhere on the form anymore in any control (outside the TPageControl).
I rebuild the application where it worked (thinking either something changed in Lazarus, or in Windows), and that application still works as I want (theming on the TPageControl is disabled).
The only difference between these 2 situations is that in the application where it works, the form is the main form.
In the application where it does not work, the form is a dialog (not the main form).
So, I put a TPageControl on the main form of the application where it did not work, disabled theming for it, and lo and behold: it worked.
After some testing I found out that the "problem" is that I use ShowModal to show the dialog form in question.
If I do a simple Show then the theming of the TPageControl is disabled, the TTabSheets have the clForm color.
Does anyone know why this is the case?
Do I use the wrong parameters for SetWindowTheme()?
Note: it returns S_OK, I checked.
Bart
KodeZwerg:
This is how I mostly did the job with Delphi to de-/activate a window theme for a particular control (and have the manifest included to use themes)
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---H:=ListBox1.Handle;T:=GetWindowTheme(H);E:=SetWindowTheme(H,NIL,'');ListBox1.Enabled:=False;ListBox1.Enabled:=True;T:=GetWindowTheme(H);
Does that help you? (I tested each times the T E H values...)
Bart:
--- Quote from: KodeZwerg on January 28, 2023, 07:47:57 pm ---This is how I mostly did the job with Delphi to de-/activate a window theme for a particular control (and have the manifest included to use themes)
Does that help you? (I tested each times the T E H values...)
--- End quote ---
No, all returned values are zero.
Note: in the main form, where this does work as expected, all returned values are zero as well.
Bart
GetMem:
@Bart
This works for me(modal form OnShow event, Lazarus Trunk/FPC 3.2.2):
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses UxTheme, LCLIntf; procedure TForm2.FormShow(Sender: TObject);begin UxTheme.SetWindowTheme(PageControl1.Handle, nil, ''); PageControl1.Invalidate;end;
Bart:
Thank you very much: that works.
The Invalidate does not seem to be necessary.
(You earned credentials in the code for that, as well as in the commit message :D )
Bart
Navigation
[0] Message Index
[#] Next page