)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to specify the custom renderer for the WinForms ScrollersFrame?

Platform: WinForms |
Control: ScrollersFrame |
Published Date: October 14, 2015 |
Last Revised Date: January 10, 2020

Custom render

You can customize the appearance of the ScrollersFrame by using the CustomRender property. To create the CustomRenderer class, you need to inherit the Syncfusion.Windows.Forms.Renderers.IRenderer interface. The IRenderer interface implements the following functions in the CustomRenderer class.

  1. DrawBackground
  2. DrawArrowButton
  3. DrawThumb

 

DrawBackground: Customizes the appearance of the ScrollersFrame.

DrawArrowButton: Draws the Arrow button used in the ScrollersFrame.

DrawThumb: Draws the thumb track used in the ScrollersFrame.

 

The following code example demonstrates the same.

C#

//Sets the custom renderer to customize the appearance of the Scrollbar.
this.scrollersFrame1.CustomRender = new BasicRenderer(true);
public class BasicRenderer : IRenderer
{
    #region class members
    /// <summary>
    /// Initializes the parent.
    /// </summary>
    protected ScrollBarCustomDraw m_parent;
    /// <summary>
    /// Indicates whether scroll is vertical or horizontal.
    /// </summary>
    protected bool m_isVerticalScroll = false;
    #endregion
    #region class initialize\finalize methods
    /// <summary>
    /// Constructor.
    /// </summary>
    /// <param name="isVerticalScrollBar"></param>
    public BasicRenderer(bool isVerticalScrollBar)
    {
        m_isVerticalScroll = isVerticalScrollBar;
    }
    /// <summary>
    /// Constructor.
    /// </summary>
    /// <param name="parent"></param>
    public BasicRenderer(ScrollBarCustomDraw parent)
    {
        m_parent = parent;
        if (parent is HScrollBarCustomDraw)
        {
            IsVerticalScrollBar = false;
        }
        else if (parent is VScrollBarCustomDraw)
        {
            IsVerticalScrollBar = true;
        }
    }
    #endregion
    #region class implements IRenderer
    /// <summary>
    /// Indicates whether Scrollbar is vertical or horizontal.
    /// </summary>
    public virtual bool IsVerticalScrollBar
    {
        get
        {
            return m_isVerticalScroll;
        }
        set
        {
            if (m_isVerticalScroll != value)
            {
                m_isVerticalScroll = value;
            }
        }
    }
    /// <summary>Draws the background.</summary>
    /// <param name="g"></param>
    /// <param name="bounds"></param>
    /// <param name="state"/>
    public virtual void DrawBackground(Graphics g, Rectangle bounds, ButtonState state)
    {
        if (null == g)
            throw new ArgumentNullException("g");
        if (bounds.Width > 0 && bounds.Height > 0)
        {
            Color backColor = SystemColors.ControlLight;
            using (Brush bgBrush = new SolidBrush(backColor))
            {
                g.FillRectangle(bgBrush, bounds);
            }
            if (state == ButtonState.Pushed)
            {
                Color clrHighlight = SystemColors.Highlight;
                Color clrSelect = Color.FromArgb(200, clrHighlight);
                using (Brush bgBrush = new SolidBrush(clrSelect))
                {
                    g.FillRectangle(bgBrush, bounds);
                }
            }
        }
    }
    /// <summary>Draws the arrow button used in the ScrollersFrame. </summary>
    /// <param name="g"></param>
    /// <param name="bounds"></param>
    /// <param name="type"></param>
    /// <param name="state"></param>
    public virtual void DrawArrowButton(Graphics g, Rectangle bounds, ScrollButton type, ButtonState state)
    {
        if (null == g)
            throw new ArgumentNullException("g");
        if (bounds.Height > 0 && bounds.Width > 0)
        {
            ControlPaint.DrawScrollButton(g, bounds, type, state);
        }
    }
    /// <summary> Draws the Thumb.</summary>
    /// <param name="g"></param>
    /// <param name="bounds"></param>
    /// <param name="state"></param>
    public virtual void DrawThumb(Graphics g, Rectangle bounds, ButtonState state)
    {
        if (null == g)
            throw new ArgumentNullException("g");
        if (bounds.Width > 0 && bounds.Height > 0)
        {
            if (state == ButtonState.Inactive)
            {
                DrawBackground(g, bounds, state);
            }
            else
            {
                ControlPaint.DrawButton(g, bounds, state);
            }
        }
    }
    #endregion
}

VB

'Sets the custom renderer to customize the appearance of the Scrollbar.
Me.scrollersFrame1.CustomRender = New BasicRenderer(True)
Public Class BasicRenderer
    Implements IRenderer
    #Region "class members"
    ''' <summary>.
   ''' Initializes the parent.
   ''' </summary>.
   Protected m_parent As ScrollBarCustomDraw
   ''' <summary>.
   ''' Indicates whether the scroll is vertical or horizontal.
   ''' </summary>.
   Protected m_isVerticalScroll As Boolean = False
   #End Region
   #Region "class initialize\finalize methods"
   ''' <summary>.
   ''' Constructor.
   ''' </summary>.
   ''' <param name="isVerticalScrollBar"></param>.
   Public Sub New(ByVal isVerticalScrollBar As Boolean)
       m_isVerticalScroll = isVerticalScrollBar
   End Sub
   ''' <summary>.
   ''' Constructor.
   ''' </summary>.
   ''' <param name="parent"></param>.
   Public Sub New(ByVal parent As ScrollBarCustomDraw)
       m_parent = parent
       If TypeOf parent Is HScrollBarCustomDraw Then
           IsVerticalScrollBar = False
       ElseIf TypeOf parent Is VScrollBarCustomDraw Then
 IsVerticalScrollBar = True
       End If
   End Sub
   #End Region
   #Region "class implements IRenderer"
   ''' <summary>.
   ''' Indicates whether the Scrollbar is vertical or horizontal.
   ''' </summary>.
   Public Overridable Property IsVerticalScrollBar() As Boolean
       Get
   Return m_isVerticalScroll
       End Get
       Set(ByVal value As Boolean)
   If m_isVerticalScroll <> value Then
      m_isVerticalScroll = value
   End If
       End Set
   End Property
   ''' <summary>Draws the background</summary>.
   ''' <param name="g"></param>.
   ''' <param name="bounds"></param>.
   ''' <param name="state"/>.
   Public Overridable Sub DrawBackground(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal state As ButtonState) Implements IRenderer.DrawBackground
       If Nothing Is g Then
          Throw New ArgumentNullException("g")
       End If
       If bounds.Width > 0 AndAlso bounds.Height > 0 Then
          Dim backColor As Color = SystemColors.ControlLight
          Using bgBrush As Brush = New SolidBrush(backColor)
              g.FillRectangle(bgBrush, bounds)
          End Using
          If state = ButtonState.Pushed Then
              Dim clrHighlight As Color = SystemColors.Highlight
              Dim clrSelect As Color = Color.FromArgb(200, clrHighlight)
              Using bgBrush As Brush = New SolidBrush(clrSelect)
                   g.FillRectangle(bgBrush, bounds)
              End Using
          End If
       End If
   End Sub
   ''' <summary>Draws the arrow button used in the ScrollersFrame </summary>.
   ''' <param name="g"></param>.
   ''' <param name="bounds"></param>.
   ''' <param name="type"></param>.
   ''' <param name="state"></param>.
   Public Overridable Sub DrawArrowButton(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal type As ScrollButton, ByVal state As ButtonState) Implements IRenderer.DrawArrowButton
    If Nothing Is g Then
      Throw New ArgumentNullException("g")
    End If
    If bounds.Height > 0 AndAlso bounds.Width > 0 Then
      ControlPaint.DrawScrollButton(g, bounds, type, state)
    End If
  End Sub
  ''' <summary>Draws the Thumb</summary>.
  ''' <param name="g"></param>.
  ''' <param name="bounds"></param>.
  ''' <param name="state"></param>.
  Public Overridable Sub DrawThumb(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal state As ButtonState) Implements IRenderer.DrawThumb
     If Nothing Is g Then
       Throw New ArgumentNullException("g")
     End If
     If bounds.Width > 0 AndAlso bounds.Height > 0 Then
       If state = ButtonState.Inactive Then
          DrawBackground(g, bounds, state)
       Else
          ControlPaint.DrawButton(g, bounds, state)
       End If
     End If
  End Sub
  #End Region
End Class

 

Before passing the custom render to the scrollersframe

Figure 1: Before passing the Custom Renderer to the ScrollersFrame

After passing the custom render to the scrollersframe

Figure 2: After passing the Custom Renderer to the ScrollersFrame

Samples:

C#: ScrollersFrame_CustomRender_C#

VB: ScrollersFrame_CustomRender_VB 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon