Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Remove border of TPageControl in custom visual styles


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 6 - Last Post: Apr 11, 2017 12:29 AM Last Post By: Martin Nijhoff Threads: [ Previous | Next ]
Martin Nijhoff

Posts: 75
Registered: 8/26/10
Remove border of TPageControl in custom visual styles  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 7, 2017 2:44 AM
Hi,

I have a VCL forms apllication with a TPageControl that has its Style property set to tsFlatButtons.

When I run the application with the default Windows theme, the TPageControl's background color matches the form's background color and it has no borders.
When I run the application with a custom visual style (e.g. 'Carbon' or 'Silver'), the TPageControl's background color still matches the form's background color, but it has a border.

I tried removing seBorder from the TPageControl's StyleElements property, but this has no effect.
If I remove seClient from the TPageControl's StyleElements property, the TPageControl has no border, but it's background color is the Windows theme's color and not that of the custom visual style.

Is there any way to remove the border of a TPageControl when using custom visual styles (without writing a new component)?

I'm using C++Builder XE6.

--
Martin
Jan Dijkstra

Posts: 206
Registered: 11/4/99
Re: Remove border of TPageControl in custom visual styles  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 7, 2017 3:53 AM   in response to: Martin Nijhoff in response to: Martin Nijhoff
Martin Nijhoff wrote:
Hi,

I have a VCL forms apllication with a TPageControl that has its Style property set to tsFlatButtons.

When I run the application with the default Windows theme, the TPageControl's background color matches the form's background color and it has no borders.
When I run the application with a custom visual style (e.g. 'Carbon' or 'Silver'), the TPageControl's background color still matches the form's background color, but it has a border.

I tried removing seBorder from the TPageControl's StyleElements property, but this has no effect.
If I remove seClient from the TPageControl's StyleElements property, the TPageControl has no border, but it's background color is the Windows theme's color and not that of the custom visual style.

Is there any way to remove the border of a TPageControl when using custom visual styles (without writing a new component)?

I'm using C++Builder XE6.

--
Martin

You probably need to replace the style hook for the page control, and implement the background rendering yourself. With custom styles, the control is overlaid by a new one (through the style hook) that takes care of the custom look rendering. The default hook for the page control probably draws the border unconditionally.

I'm wrestling with the style hook system myself for my custom list views. The default Windows horizontal and vertical scrollers are overlaid with new ones by the style engine, and I haven't managed to the the communication of the position of the thumb correct at this point.

Unfortunately, it is very poorly documented. Basically, you have to wade through the pascal sources to figure out how it works.
Martin Nijhoff

Posts: 75
Registered: 8/26/10
Re: Remove border of TPageControl in custom visual styles  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 10, 2017 3:06 AM   in response to: Jan Dijkstra in response to: Jan Dijkstra
Thanks for your reply, Jan.

You probably need to replace the style hook for the page control, and implement the background rendering yourself.

That seems a bit overkill, just to fill the background with the visual style's background color.

As an alternative, I added this code to the OnShow handler of the form:

PageControl->StyleElements >> seClient;
PageControl->Brush->Color = StyleServices()->GetStyleColor(scWindow);


This works for most custom visual styles, except for those that use a textured background (e.g. 'Diamond' or 'Glossy').

In the end, I 'solved' the problem by placing the TPageControl inside a TPanel and sizing the TPageControl so that its border gets clipped by the TPanel. Not the most elegant solution, but it works.

I'm wrestling with the style hook system myself for my custom list views. The default Windows horizontal and vertical scrollers are overlaid with new ones by the style engine, and I haven't managed to the the communication of the position of the thumb correct at this point.

I noticed that too. When setting the LeftCol and TopRow properties of a grid (TStringGrid, TDrawGrid, etc.) doesn't update the scroll bar's thumb position when visual styles are used. Only when you move the mouse cursor off the grid, the visual style's scroll bar thumb position is updated.

Unfortunately, it is very poorly documented. Basically, you have to wade through the pascal sources to figure out how it works.

I found that the style hook for a TPageControl is TTabControlStyleHook, which is located in Vcl.ComCtrls.pas. The border is painted by the call to DrawElement() in TTabControlStyleHook::WMEraseBkgnd(). However, I've been unable to find out exactly which DrawElement() gets called and in which .pas file it is located.

--
Martin
Asger Joergensen

Posts: 370
Registered: 11/18/08
Re: Remove border of TPageControl in custom visual styles  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 10, 2017 5:20 AM   in response to: Martin Nijhoff in response to: Martin Nijhoff
Hi Martin

Martin Nijhoff wrote:

In the end, I 'solved' the problem by placing the TPageControl inside a TPanel
and sizing the TPageControl so that its border gets clipped by the TPanel. Not
the most elegant solution, but it works.

Remember to check your solution on large DPI, a lot of things doesn't scale correctly,
when using the new designer.

Best regards
Asger
Martin Nijhoff

Posts: 75
Registered: 8/26/10
Re: Remove border of TPageControl in custom visual styles  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 11, 2017 12:29 AM   in response to: Asger Joergensen in response to: Asger Joergensen
Remember to check your solution on large DPI, a lot of things doesn't scale correctly,
when using the new designer.

Thanks for the tip, Asger.

--
Martin
Harry Bego

Posts: 22
Registered: 1/27/09
Re: Remove border of TPageControl in custom visual styles  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 10, 2017 2:55 AM   in response to: Martin Nijhoff in response to: Martin Nijhoff
The simple solution is to use a TTabControl instead of a TPageControl, and TPanels instead of TTabSheets. Use TabControl1Change() to show a TPanel based on the TabIndex.
Martin Nijhoff

Posts: 75
Registered: 8/26/10
Re: Remove border of TPageControl in custom visual styles  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 10, 2017 3:14 AM   in response to: Harry Bego in response to: Harry Bego
Thanks for your reply, Harry.

The simple solution is to use a TTabControl instead of a TPageControl, and TPanels instead of TTabSheets. Use TabControl1Change() to show a TPanel based on the TabIndex.

I forgot to mention that I set the TabVisible property of the TTabSheets to 'false', to hide the tabs. The TPageControl is used to show different controls in response to the user selecting an item from a TTreeView. I could have used a bunch of TPanels for that, but TPageControl works better for me.

--
Martin
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02