Having moved to .net 2.0 I love the new ToolStripContainer, however it
is causing me some issues with colours in the rest of my application.
With visual styles enabled the ToolStripPanel is a blue gradient, from
light blue on the right, to a darker blue on the left.
I would really like the content panel of the ToolStripContainer to
match this colour scheme. I can change the back colour to a light
blue, but not with a gradient. I have used InactiveCaptionText
however this is too light, but is the closest I can get to the lighter
blue using the system colours.
How can I change it? I know I can use a custom colour, but then if it
is run on a system with a different colour scheme it will look
strange, which is why i would like to stick with system colours.
Incidentally I notice that outlook 2003 uses a solid colour, however
that colour does match the lighter of the two blues. This makes me
think that a gradient isnt possible, but somehow you can select the
lighter of the two colours.
Hope this all makes sense, any enlightenment will be greatfully
received!
Brian Sokolnicki - 09 Feb 2007 19:49 GMT
It think this is what your looking for. I have attached code below. Chang
the code to use system colors.
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Reflection;
#endregion
namespace MicroTek.RMS.CustomUserControl
{
public class FormHeaderTitleStrip : ToolStrip
{
private FormHeaderTitleStripRenderer _renderer;
public FormHeaderTitleStrip()
{
// Set defaults
this.GripStyle = ToolStripGripStyle.Hidden;
// Set renderer
this._renderer = new FormHeaderTitleStripRenderer();
// Look for headerText
this.Renderer = this._renderer;
}
}
#region Custom ToolStrip Renderer
internal class FormHeaderTitleStripRenderer :
ToolStripProfessionalRenderer
{
public FormHeaderTitleStripRenderer()
: base(new FormHeaderTitleColorTable())
{
this.RoundedEdges = false;
}
protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs
e)
{
base.OnRenderToolStripBorder(e);
}
}
internal class FormHeaderTitleColorTable :
System.Windows.Forms.ProfessionalColorTable
{
public override Color ToolStripGradientBegin
{
get
{
return Color.FromArgb(114, 136, 172);
}
}
public override Color ToolStripGradientMiddle
{
get
{
return Color.FromArgb(114, 136, 172);
}
}
public override Color ToolStripGradientEnd
{
get
{
return Color.FromArgb(114, 136, 172);
}
}
public override Color ToolStripBorder
{
get
{
return Color.Black;
}
}
}
#endregion
}
> Having moved to .net 2.0 I love the new ToolStripContainer, however it
> is causing me some issues with colours in the rest of my application.
[quoted text clipped - 19 lines]
> Hope this all makes sense, any enlightenment will be greatfully
> received!
Kevin - 12 Feb 2007 10:30 GMT
Thanks for your reply Brian, but I'm not sure this is what I am after.
Your code seems to create a toolstrip with a custom gradient (or in
your case, a solid colour), but i want my panel to have the same
gradient as the toolstrip panel.
However, it has opened my eyes to the ProfessionalColorTable class, so
I will investigate that.
Thanks
Kevin
Kevin - 12 Feb 2007 11:21 GMT
ok, I have discovered the ProfessionalColor class.
If I set the back color of my control to be
ProfessionalColors.RaftingContainerGradientEnd at runtime it sets it
to the correct colour.
Interestingly though I cant choose this colour at design time. Does
anyone know why?
Also if I change my theme whilst my program is running all the
toolbars etc on my program change to the correct colour but my
usercontrol remains the old colour. Obviously this is a very minor
thing, but is there something else I should be doing? I cant bind to
it because it says that ProfessionalColor is a type and cannot be used
in an expression.
Thanks for your help
Kevin