Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, December 14, 2010 8:01 AM
I have set a scrollable control's autoscroll to true.
What do you do when you don't want a scroll to occur?
For example, suppose you have a RichTextBox and a button side by side as below:
Notice that "button1" has the focus. If you click on the RichTextBox to give it focus, the scroll bars will scroll until the upper left corner of the RichTextBox is in view.
But what if, for whatever reason, you wanted to keep button1 in view? How would you do that?
All replies (6)
Wednesday, December 15, 2010 3:10 AM âś…Answered | 1 vote
imports Imports System.Windows.Forms
Public Class myPanel
Inherits Panel
Protected Overrides Function ScrollToControl(ByVal activeControl As System.Windows.Forms.Control) As System.Drawing.Point
Return DisplayRectangle.Location
End Function
End Class
Define your own custom Panel and overrides function ScrollToControl by returning DisplayRectangle.Location
Works for me.
Tuesday, December 14, 2010 8:29 AM
First of all I do not think what you have done is a good way to go about. Rich Text box itself provides both horizontal and vertical scroll bars. Why are you not using those?
Tuesday, December 14, 2010 8:44 AM
Tsluu,
Then you should not have that button in your usercontrol, and then it makes no sense to make a usercontrol from this, because the only reason that you do that is that you want to scroll the button with the RichTextbox.
So together with your question is your usercontrol senseless
Success
Cor
Tuesday, December 14, 2010 8:50 AM
The easiest way is to move button1 out of the container on to the form.
If you drag and position it it is most likely that it will go into the container. So use the Outline Window to position with the correct parent. Put it directly on the form instead of your container.
Pradeep, Microsoft MVP (Visual Basic)
Tuesday, December 14, 2010 2:40 PM
When a child control gets focus and AutoScroll is true in a panel control, the scroll bar for the parent will immediatly scroll to ensure the selected control is in view. This is undesireable when dealing with several large controls in a panel as it causes unwanted movement. Is there a way to disable or override this action?? I would like for it to only move with the scrollbar not any auto movement.
Tuesday, December 14, 2010 7:29 PM
Set the AutoScroll = False and AutoSize = True.
Add your own scrollbar instead of the Panel's scrollbar and you should be done. :)
Pradeep, Microsoft MVP (Visual Basic)