Custom Toolbar colours

sfx

Well-known member
Joined
Jan 31, 2006
Messages
46
Programming Experience
Beginner
Hello All,

Can anyone help me in changing the colour of a created toolbar so that it looks the same as the toolbars in the Visual Studio IDE itself? The standard created colour is blue with a lower shadow. I am trying to develop the same colour and shadowing as Visual Studio. Likewise, I am also unable to change the colour and shadowing on the drop down menus of a created menu bar so that they look like Visual Studio's.

Cheers,

sfx

P.S. I am using Visual Basic 2005 Express
 
Toolbar: "Change the 'BackColor' of the container you are placing the toolbar in, then set its 'Appearance' to 'Flat'."

Why don't you just use the new ToolStrip, much better and easier to use.
 
Hi John,

Thanks for the swift reply. I'm sorry for not mentioning it earlier, but I have been using the toolstrip and menustrip objects within forms. I have experimented with various appearance properties for both and have been unable to make them look like the menu and tool bars inherent within Visual Studio. For instance, when I change the "BackColor" property of a toolstrip object so that it resembles the colour of Visual Studio's standard tool bar, the toolstrip loses its shadow and appears flat. This is where I am coming undone.

I apologise if there are obvious answers to my questions, but I am only a newbie to VB and VS.

Cheers,

sfx
 
Yes, that is true, you did say wanted that 'look', but the result is a flat color.
Well, there is a solution, it is little bit difficult to explain and do, but I will give you some code easy to put into project that will give the requested result.
The solution is to create a custom Renderer class inherited from ToolStripRenderer class and assign it to the Toolbar.Renderer property. Inside the renderer add code to draw gradient backcolor. This still display a flat style in designer view, but will display fine when run. Solution is to create an inherited Toolstrip with the same code added, this will draw custom gradients in designer, too.
Here is the code for the renderer:
VB.NET:
Public Class thisRenderer
Inherits System.Windows.Forms.ToolStripRenderer
  Protected Overrides Sub OnRenderToolStripBackground(ByVal e As ToolStripRenderEventArgs)
    MyBase.OnRenderToolStripBackground(e)
    Dim b As New Drawing2D.LinearGradientBrush(e.AffectedBounds, Color.WhiteSmoke, e.BackColor, _
Drawing2D.LinearGradientMode.Vertical)
    e.Graphics.FillRectangle(b, e.AffectedBounds)
  End Sub
End Class
 
'   this could be called in a form like this:
[SIZE=2]' ToolStrip1.Renderer = [/SIZE][SIZE=2][COLOR=black]New[/COLOR][/SIZE][SIZE=2] myRenderer
[/SIZE]
I have attached a ToolStrip control that adds this behaviour.

If you don't know how to add an existing custom control to an application:
Put the two files in application folder, 'add existing item' in Solution Explorer (select myToolStrip.vb), rebuild, then add one myToolstrip to form from Toolbox.

Now you can select what BackColor you want and it will display with the standard gradient "shadow".
 

Attachments

  • myToolstrip.zip
    1.1 KB · Views: 128
Some more info, and perhaps a fix. In the haste I inherited from the base class of ToolStripRenderer, perhaps better to inherit from ToolStripSystemRenderer or ToolStripProfessionalRenderer, both will display grips correctly when visible (in different styles) without extra code.
 
Hi John,

Thanks very much for going to so much trouble for me. I appreciate it. Your code was a little advanced for me but I managed to get it working nonetheless. It seems strange to me why Microsoft did not provide this kind of encapsulated customisation within their own classes. Perhaps a future release will rectify this. In the meantime, however, do you happen to know of any third party apps that might provide features similar to that which I have been asking about?

Cheers,

sfx
 
Why is it that it's always those with the least experience who want the fanciest features? :) Microsoft have provided some really good UI elements in the .NET Framework. They have also provided the ability customise those controls, but to do so is an advanced feature because it uses some very powerful functionality. With power comes complexity. I would really recommend that you concentrate on writing good code and making your UI as user-friendly as possible before worrying about the colour of your toolbar, which really comes under the bells-and-whistles category. Microsoft is multi-billion dollar company, so of course they're going to go the extra mile with their UI. There are also many third-party UI elements available that are even more whizz-bang than some of Microsoft's, but the prices of most of them should indicate the amount of work that has gone into producing them.
 
sfx, about encapsulation, the renderer class is useful for several different classes, so the way they are doing this is called Object Oriented Programming (OOP) and is the fundamental programming model of .Net and the paradigm of most programming languages today.
 
Hi jmcilhinney,

Why is it that it's always those with the least experience who want the fanciest features?”

Because inexperience is a bedfellow to curiosity. Ergo, it is not uncommon for people in my situation to be full of ideas but lack the necessary direction in order to make prudent programming decisions. Keep in mind that I am only a newbie, and hence this status limits my ability, at present, to confront programming from a strictly pragmatic perspective rather than one of curious enthrallment. However, I do appreciate your comments and will endeavour to focus on streamlining my program code rather than becoming waylaid by aesthetics.

John, thanks again for your assistance.

Cheers,

sfx
 
sfx, did you see that the MenuStrip also can take a custom Renderer ?
 
Hi John,

Yes, I noticed that but I think I will take jmcilhinney's advice and leave more complex programming until I can better understand the concepts and logic involved.

Thanks again,

sfx
 
Back
Top