Category / Section
How to avoid AutoScroll behavior in WinForms XPTaskBar when control is selected?
1 min read
Avoid AutoScroll behavior
XPTaskBar is a container control, which displays Scrollbar when its child items bound exceeds its bounds. As like in Panel, when a child control is selected in XPTaskBar it will be Auto scroll and bring the selected control into view. This behaviour can be resolved by following below steps.
1. Need to create Custom control, which is derived from XPTaskBar.
2. Need to override its ScrollToControl function and maintain its scroll position.
C#
protected override System.Drawing.Point ScrollToControl(System.Windows.Forms.Control activeControl) { // Returning the current location prevents the XPTaskBar from // scrolling to the active control when the panel loses and regains focus return this.AutoScrollPosition; }
VB
Protected Overrides Function ScrollToControl(ByVal activeControl As System.Windows.Forms.Control) As System.Drawing.Point ' Returning the current location prevents the XPTaskBar from ' scrolling to the active control when the panel loses and regains focus Return Me.AutoScrollPosition End Function
Figure 1. Avoid XPTaskBar to scroll automatically with image.
Samples: