Vegito_ZA Vegito_ZA - 2 years ago 96 Question

How do I first capture and then set scrollbar's position?

I have a program that stores data. A form creates a panel with read only text boxes for each result found in my database query. The Form has autoscroll set to True. When the user clicks on a specific record's update button another form opens to handle the update. The first form then clears all controls and redraws them to reflect the update. My Problem: The redrawn form's scrollbar is always at the top. I want the scrollbar to scroll back to its position before the update. Please help.

Answer Source

You can read and set Form.HorizontalScroll.Value and Form.VerticalScroll.Value.
You can also check Form.HorizontalScroll.Visible, but the .value is 0 if it is not visible, so this should be irrelevant.

Don't go over the maximum when recalling, e.g.
frm.HorizontalScroll.Value = Math.Min(SavedValueH, frm.HorizontalScroll.Maximum)

However, Winforms has some problems when the scrollvalue is set through code, see answers to this question.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download