如何在 C# 中确定面板的完整大小(包括滚动条)
我遇到的问题是面板大小为 200x200 像素。对于我正在编写的程序,在任何给定时间我都需要知道该面板有多大,但这会变得很困难,因为自动滚动处于打开状态并且插入大量内容时面板会展开(并获得滚动条)。
我稍微研究了 AutoScrollPosition 和 AutoScrollOffset,甚至尝试在我的解决方案中实现这一点 - 但看起来这只会告诉您当滚动条位于某个位置时有关面板的信息 - 而在任何给定时间我都需要知道面板的总大小。
所以基本上,假设一些内容被输入到面板中,考虑到滚动距离,它实际上变成了一个 600x750 像素的面板。有谁知道我可以通过什么方式真正获得这些信息?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“包括滚动条”条款使这个问题无法回答。因为滚动条仅应用于 DisplayRectangle。
您可以从 PreferredSize 属性获取所需的面板大小,这样就不需要滚动条了。您可以从 SystemInformation.HorizontalScrollBarHeight 和 VerticalScrollBarWidth 属性获取滚动条的高度和宽度。
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.
当Panel的内容大于其ClientSize时,AutoScrollMinSize应该等于Panel的可滚动区域。
When the contents of the Panel are bigger than its ClientSize, then AutoScrollMinSize should be equivalent to the scrollable area of the Panel.