开发者

How to fix scrollbars when the window or container is resized?

Currently in my application I am using the HScrollBar and VScrollBar for panning arou开发者_如何学编程nd in a large image. The part of the image that is shown is based on the scrollbar's Value property. However, when resizing the SplitContainer or resizing the form window the scrollbar's Value does not automatically update and it may render something off-screen.

At this point I noticed that if you clicked the scrollbar's arrow it magically fixes the scrollbar. I was wondering if there was any way to simulate clicking the scrollbar to do this in the Form_Resize and SplitContainer_Resize event handlers but I couldn't find anything.

Having to manually adjust the scrollbar's value in all resizing events is slow, ugly, and doesn't work well. I'd really like for the scrollbar to just automatically fix itself when the window resizes like it does when you click its arrow but I'm not sure how.


Try calling the scrollbar's Invalidate() method in the form's resize event handler:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invalidate.aspx

That should cause it to redraw correctly after the form is resized.


Use something like this:

HScrollBarObject.SetStyle(ControlStyles.ResizeRedraw, true);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜