How to fine out the length(size) of vertical scrol开发者_StackOverflow社区l bar? I have 5 pages in a document, that take 5 page down command to go to bottom.i want to find out the length of the scroll bar that the five pages are going to take in total. Is there a way i can find out the total length/size of scroll bar for that, in C#?
I will assume you're using the standard .net VScrollBar control. The control has Maximum and Value properties. Maximum controls the maximum value for value. There are also the SmallChange and LargeChange properties which will need to be set.
Also I assume you'll need to vary the maximum value depending on the document you read in, therefore, you'll set these in code, versus design time.
So in your scenario above, we could write the following code, to get the desired behavior of snapping to each of the 5 positions while scrolling or paging up and down.
void LoadDocument(string documentName) {
//...
int pages=doc.PageCount; // assume 5 for now
vScrollBar1.Maximum = pages;
vScrollBar1.Value = 0; // set it to the first page on load.
vScrollBar1.LargeChange = 1; // this forces page-by-page navigation.
//(Not recommended on large documents, FYI)
// ...
}
精彩评论