Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the full size of a Panel (including scroll bars) in C#

The problem I am having is with a panel, which starts at the size 200x200 pixels. For the program I am writing, at any given time I need to know how big this panel is, but this gets difficult as AutoScroll is on and when large content is inserted the panel expands (and gets scroll bars).

I have looked a bit at AutoScrollPosition and AutoScrollOffset, and even tried implementing this in my solution - but it appears this only tells you information about the panel when the scroll bar is in a certain position - whereas at any given time I need to know the total size of the panel.

So basically, suppose some content got entered into the panel and taking the scrolling distance into account it really became a 600x750 pixel panel. Does anyone know of any way I can actually get this information?

Thanks

like image 414
utterly_confused Avatar asked Oct 11 '22 09:10

utterly_confused


1 Answers

The "including scroll bars" clause makes the question unanswerable. Because the scrollbars are only applied to the DisplayRectangle.

You can get the required size of the panel so that no scrollbars are necessary from the PreferredSize property. You can get the height and width of the scrollbars from the SystemInformation.HorizontalScrollBarHeight and VerticalScrollBarWidth properties.

like image 149
Hans Passant Avatar answered Oct 13 '22 09:10

Hans Passant