How to specify the custom renderer for the WinForms ScrollersFrame?
Custom render
You can customize the appearance of the WinForms 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.
- DrawBackground
- DrawArrowButton
- 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
Figure 1: Before passing the Custom Renderer to the ScrollersFrame
Figure 2: After passing the Custom Renderer to the ScrollersFrame
Samples:
C#: ScrollersFrame_CustomRender_C#
VB: ScrollersFrame_CustomRender_VB
Conclusion
I hope you enjoyed learning about how to specify the custom renderer for the WinForms ScrollersFrame.
You can refer to our WinForms ScrollersFrame’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms ScrollersFrame documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms ScrollersFrame and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!