Container for VisualStyles

G

Guest

Is there a Windows.Forms 2.0 container that implements Windows XP VIsual
Styles?

I know the TabControl does but I need a non-tabbed container that does so as
well in order to match the appearance of a TabControl in my application.
Currently, I am using a panel but with the Windows XP theme turned on, the
TabControl background turns light (is it white? I can't tell for sure) but
the background of the panel control used alongside the TabControl stays gray.

Thanks in advance,

Dale
 
L

Linda Liu [MSFT]

Hi Dale,

When we apply Windows XP Visual Styles to an application, all the controls
in the application will take a Windows XP look.

However, each control may have a different appearance for Windows XP Visual
Styles. For example, the TabControl control's background has a light color
but the Panel control's background has a gray color. In addition, if the
Appearance property of the TabControl is set to Buttons or FlatButtons, its
background color will turn to gray color.

You have mentioned that you want a non-tabbed container that match the
appearance of a TabControl in your application. Why not use a TabControl
and removing all the tabpages within it?

Hope this helps.
If my suggestion is not appropriate to your scenario, please feel free to
let me know.



Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

I thought your idea was a great one but then, when I tried it, I found out
that you cannot add controls to a TabControl. Apparently, the only conrol
that can be added to a TabControl is a TabPage.

My situation is this: I have two views of my data - simple and advanced.
In simple mode, all of the data fits on one form. In advanced, it takes 4
tabs to view the data. When the user selects simple view, it goes against
Microsoft's usability guidelines for the TabControl to use the TabControl
with only one tab. But I still need the user experience to be the same as
the advanced view but just no tabs.
 
L

Linda Liu [MSFT]

Hi Dale,

Thank you for your reply.

Yes, you're right. We could only place TabPage on a TabControl control.

As for a workaround for your scenario, I suggest that you add a TabPage on
the TabControl to display the data in simple mode and draw the TabControl
control by custom code using VisualStyleRenderer class. To do this, we
could derive a new control from TabControl class. In the derived class, set
the ControlStyles.UserPaint to true and override the OnPaint method to draw
the TabPage. Note that we don't draw the tab of the TabPage in order to
hide it.

The following is a sample.

using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using System.Drawing;

class MyTabControl : TabControl
{
public MyTabControl()
{
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
DrawControl(e.Graphics);
}

private void DrawControl(Graphics g)
{
if (!Visible)
{
return;
}
VisualStyleRenderer render = new
VisualStyleRenderer(VisualStyleElement.Tab.Pane.Normal);
Rectangle TabArea = this.DisplayRectangle;
TabArea.Y = TabArea.Y + 1;
TabArea.Width = TabArea.Width + 1;
int nDelta = SystemInformation.Border3DSize.Width;
TabArea.Inflate(nDelta, nDelta);
render.DrawBackground(g, TabArea);
}
}

Build the project and drag MyTabControl from Toolbox on your form. You add
only one TabPage on the MyTabControl control and then add some controls
you'd like on the TabPage.

Hope this helps.
If you have anything unclear, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
G

Guest

Thank you. I think between Mick and this, I will have my problem solved.

Regards,

Dale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top