Nevron .NET Vision Documentation
Extending the Manager

Overview
The NCommandBarsManager component is highly customizable regarding behaviour and children elements appearance. Being the root element of the docking toolbars framework, all commands delegate their functionality to the manager, which makes it possible to perform application specific customizations at the manager's level.
Customizing Appearance

You can customize the appearance of the entire framework by using the manager's Palette property.
The following example demonstrates how to change the look-and-feel of the framework by using a predefined ColorScheme:

C#
Copy Code
this.nCommandBarsManager.Palette.Scheme = ColorScheme.LunaSilver;
Visual Basic
Copy Code
Me.nCommandBarsManager.Palette.Scheme = ColorScheme.LunaSilver
For more information about palettes see Using Palettes.

You may also extend docks by providing your custom renderers.
The following example demonstrates how to achieve this:

C#
Copy Code
//create a class that derives from the default NToolbarDockRenderer
public class MyToolbarDockRenderer : NToolbarDockRenderer
{
    public MyToolbarDockRenderer()
    {
    }

    protected override void DrawParentBackground(Graphics g)
    {
  Control dock = Parent;
  if(dock == null)
       return;

  Rectangle bounds = dock.ClientRectangle;
  Color begin = Color.FromArgb(51, 51, 51);
  Color end = NColorHelper.LightLight(begin);

  //create a gradient like one found in Longhorn
  LinearGradientBrush brush = new LinearGradientBrush(bounds, begin, end, 0.0f, false);

  brush.SetSigmaBellShape(0.5f);

  g.FillRectangle(brush, bounds);

  Font f = null;

  try
  {
       //draw sample text
       f = new Font("Trebuchet MS", 14, FontStyle.Bold);
       //use cashed renderer's brush to speed up performance
       Brush.Color = Color.Yellow;
       g.DrawString("Longhorn Style Toolbar Dock", f, Brush, bounds, StringFormat);
  }
  finally
  {
       brush.Dispose();
       if(f != null)
            {
                f.Dispose();
            }
  }
    }
}

//assign an instance of this renderer to the top dock
this.nCommandBarsManager.GetDock(DockStyle.Top).Renderer = new MyToolbarDockRenderer();
Visual Basic
Copy Code
'create a class that derives from the default NToolbarDockRenderer
Public class MyToolbarDockRenderer 
   Inherits NToolbarDockRenderer
    Public Sub New()
    End Sub

    Protected Overrides Sub DrawParentBackground(ByVal g As Graphics)
        Dim dock As Control = Parent
        If dock == null Than 
            return
        End If

        Dim bounds As Rectangle = dock.ClientRectangle
        Dim beginColor As Color = Color.FromArgb(51, 51, 51)
        Dim endColor As Color = NColorHelper.LightLight(beginColor)

        'create a gradient like one found in Longhorn
        Dim brush As LinearGradientBrush = New LinearGradientBrush(bounds, beginColor, endColor, 0.0F, False)

        brush.SetSigmaBellShape(0.5F)

        g.FillRectangle(brush, bounds)

        Dim f As Font = Nothing

        Try
            'draw sample text
            f = New Font("Trebuchet MS", 14, FontStyle.Bold)
            'use cashed renderer's brush to speed up performance
            Brush.Color = Color.Yellow
            g.DrawString("Longhorn Style Toolbar Dock", f, Brush, bounds, StringFormat)
        Finally
            brush.Dispose()
            If f <> Nothing Than 
                f.Dispose()
            End If
        End Finally
    End Sub
End Class

'assign an instance of this renderer to the top dock
Me.nCommandBarsManager.GetDock(DockStyle.Top).Renderer = New MyToolbarDockRenderer()

The result of our custom renderer.

Providing Custom Behaviour

The behaviour of the NCommandBarsManager component can be extended with ease. All notifications and framework specific methods are overridable, thus allowing you to provide custom functionality/implementation.

The following example demonstrates how to extend the OnQueryCommandUIState method:

C#
Copy Code
//override the method and provide custom logic
protected override void OnQueryCommandUIState(ref NCommandUIState state)
{
    NCommandContext context = state.Context;
    if(context != myContext)
    {
  base.OnQueryCommandUIState(ref state);
  return;
    }

    //apply our custom logic for the specified context
    state.ImageIndex = 0;
    state.Enabled = this.CanEnableMyContext();
}
Visual Basic
Copy Code
'override the method and provide custom logic
Protected Overrides Sub OnQueryCommandUIState(ByRef state As NCommandUIState)
    Dim context As NCommandContext = state.Context
    If context <> myContext Than
        MyBase.OnQueryCommandUIState(state)
        Return
    End If

    'apply our custom logic for the specified context
    state.ImageIndex = 0
    state.Enabled = Me.CanEnableMyContext()
}
See Also

 

 


©2017. Nevron Software LLC.

Send Feedback