User Interface for .NET / User's Guide / Docking Panels / Docking Framework Renderer

Docking Framework Renderer
 Overview
By default all UI elements of the docking framework are painted by a separate class - NDockingFrameworkRenderer - and by default there is only one instance of it - field of the NDockManager component. You can easily extend an existing method or create an entirely custom renderer deriving from the base one. You can specify the renderer either at the manager's level, thus changing the entire framework's appearance, or per panel, changing the panel itself.
 Renderer's Methods

The following table describes methods that are available to you to extend:

Method Description
 DrawCaption Renders a caption using the specified context.
 DrawCaptionGradient Renders a gradient-style caption using the specified context.
 DrawCaptionWinDef Renders a caption when the current ColorScheme is WindowsDefault
 DrawCaptionText Renders the text of a caption using the specified context.
 DrawCaptionButton Renders a caption's child button.
 DrawFrame Renders a floating panel frame using the specified context.
 DrawGripper Renders a gripper using the specified context.

 

 Creating And Providing Custom Renderer

The following code demonstrates how to create and apply your custom docking framework renderer:

C#
Copy Code
public class MyDockingFrameworkRenderer : NDockingFrameworkRenderer
{
    public MyDockingFrameworkRenderer()
    {

    }

    public override void DrawFrame(NRenderFrameContext context)
    {
        Rectangle r = context.Bounds;
        r.Width -= 1;
        r.Height -= 1;
        NUIRenderer.DrawBorder3D(context.Graphics, r, BorderStyle3D.Raised, SystemColors.ControlDark, Color.Empty);
    }

    public override void DrawCaption(NRenderCaptionContext context)
    {
        if(context.IsActive)
        {
            DrawActiveCaption(context);
        }
        else
        {
            DrawInactiveCaption(context);
        }

        if(context.DrawGripper)
        {
            DrawGripper(context);
        }

        DrawCaptionButtons(context);
        DrawCaptionText(context);
    }

    protected virtual void DrawActiveCaption(NRenderCaptionContext context)
    {
        Color begin = SystemColors.ActiveCaption;
        Color end = NColorHelper.ActiveCaptionGradient;

        LinearGradientBrush br = new LinearGradientBrush(context.CaptionBounds, begin, end, 0.0f);
        context.Graphics.FillRectangle(br, context.CaptionBounds);
        br.Dispose();
    }

    protected virtual void DrawInactiveCaption(NRenderCaptionContext context)
    {
        Color begin = SystemColors.ControlDark;
        Color end = SystemColors.Control;

        LinearGradientBrush br = new LinearGradientBrush(context.CaptionBounds, begin, end, 0.0f);
        context.Graphics.FillRectangle(br, context.CaptionBounds);
        br.Dispose();
    }
}

//apply this render to an existing NDockManager
this.nDockManager1.Renderer = new MyDockingFrameworkRenderer();
Visual Basic
Copy Code
Public Class MyDockingFrameworkRenderer
    Inherits NDockingFrameworkRenderer 
    Public Sub New() 
    End Sub

    Public Overrides Sub DrawFrame(ByVal context As NRenderFrameContext)
        Dim r As Rectangle = context.Bounds
        r.Width -= 1
        r.Height -= 1 
        NUIRenderer.DrawBorder3D(context.Graphics, r, BorderStyle3D.Raised, SystemColors.ControlDark, Color.Empty)
    End Sub

    Public Overrides Sub DrawCaption(ByVal context As NRenderCaptionContext)
        If context.IsActive Then
            DrawActiveCaption(context)
        Else
            DrawInactiveCaption(context)
        End If

        If context.DrawGripper Then
            DrawGripper(context)
        End If

        DrawCaptionButtons(context)
        DrawCaptionText(context)
    End Sub

    Protected Overridable Sub DrawActiveCaption(ByVal context As NRenderCaptionContext)
        Dim beginColor As Color = SystemColors.ActiveCaption
        Dim endColor As Color = NColorHelper.ActiveCaptionGradient
        Dim br As LinearGradientBrush = New LinearGradientBrush(context.CaptionBounds, beginColor, endColor, 0.0F)
        context.Graphics.FillRectangle(br, context.CaptionBounds)
        br.Dispose()
    End Sub

    Protected Overridable Sub DrawInactiveCaption(ByVal context As NRenderCaptionContext)
        Dim beginColor As Color = SystemColors.ControlDark
        Dim endColor As Color = SystemColors.Control
        Dim br As LinearGradientBrush = New LinearGradientBrush(context.CaptionBounds, beginColor, endColor, 0.0F)
        context.Graphics.FillRectangle(br, context.CaptionBounds)
        br.Dispose()
    End Sub

End Class

'apply this render to an existing NDockManager

Me.nDockManager1.Renderer = New MyDockingFrameworkRenderer()

Following are screenshots of the result from the above code:

 

A NDockingPanel in active and inactive state. 

See Also