Reputation: 354
I am not sure if it is a duplicate question but I could not find any answer on StackOverflow.
Problem Statement: I have Third party Image Viewer and PDF viewer controls. which are embedded into C# WinForms page. I want to control scrollbars movement in percentage. For example, if I press "down" key then vertical scroll bar should move down to 20% of page height. I have tried with below logic:
_imageViewer.VerticalScrollBar.Value += _imageHeight X ZoomFactor X .20
OR
_imageViewer.VerticalScrollBar.Value += pdfViewer1.VerticalScroll.Maximum X .20
Both approaches are not giving me the exact result. I think I should also consider thumb size of scroll bar but I don't know how can I get that value.
Please suggest me any good approach to moving scrollbar in the percentage of image height or width.
Upvotes: 1
Views: 1905
Reputation: 125207
You can assign SmallChange
property of ScrollBar
to suitable value. As mentioned in documentations, When the user presses one of the arrow keys or clicks one of the scroll bar buttons, the Value
property changes according to the value set in the SmallChange
property.
Example:
vScrollBar1.SmallChange = ((vScrollBar1.Maximum - vScrollBar1.Minimum) * 20 / 100);
Upvotes: 2