Scrollbar centering on its own

Asked

Viewed 161 times

1

I have a form with height larger than the screen, with many buttons and checkboxes, The user uses the scroll bar to scroll down and see all the content of the form.

My problem is that every time the user tries to click a button or checkbox, the form tries to center that button in the middle of the user’s screen, rolling the scroll bar by itself. This disturbs too much, sometimes you are reading something and need to activate a button, the form tries to center this button and scrolls the scroll bar, sometimes causes the user to lose the click and has to click again.

I saw that this is the default property behavior Autoscroll = true; But they move to Autoscroll=false, the scroll bar disappears.

Is there a way to fix this? Use visual studio 15, winforms

  • Why does the form center button?

  • That, I don’t want the panel to try to center the clicked item by rolling the scroll bar alone. I want the scroll bar to be where the user left it, even if the button he will click is right in the corner of the screen.

1 answer

2

It really is the standard behavior of scroll, trigger the event ScrollToControl passing the control that was clicked.

You can overwrite this event in the container of its elements by returning DisplayRectangle.Location.

protected override Point ScrollToControl(System.Windows.Forms.Control activeControl)
{
    return DisplayRectangle.Location;
}
  • Thank you my friend, but I did not understand how to implement this code you passed. Where I type this code?

  • As I said, you need to override the event in the control that is container of the elements. If the elements are loose in the form, you need to put in the form. If they are on a panel, you will need to create a new class inheriting from Panel, write this method and then change your current panel to what was created.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.