简体   繁体   English

在wxWidgets中,有没有一种方法可以避免在调整窗口大小时仅部分显示按钮?

[英]In wxWidgets, is there a way to avoid buttons showing only partially when window is resized?

I am just starting with wxWidgets and I could not find a way to make the buttons inside a sizer to always show at their full size 我只是从wxWidgets开始,我找不到一种方法来使sizer中的按钮始终以完整尺寸显示

ie. 即。 the user should not be allowd to lessen the window size too much. 不应允许用户减小窗口大小。

Any help will be appreciated. 任何帮助将不胜感激。

wxTopLevelWindow::SetMinSize allows you to set the minimum size that your window can be resized to. wxTopLevelWindow :: SetMinSize允许您设置窗口可调整大小的最小大小。 You can always make it small programmatically if needed. 如果需要,您总是可以通过编程将其缩小。

Use GetSizer()->Fit() when you finish adding controls to layout. 完成将控件添加到布局时,请使用GetSizer()-> Fit()。

http://docs.wxwidgets.org/2.9.4/classwx_sizer.html#abad9cedc0cbe9ade2c799da23462d17e http://docs.wxwidgets.org/2.9.4/classwx_sizer.html#abad9cedc0cbe9ade2c799da23462d17e

Just noticed that you want to prevent the user . 只是注意到您要阻止用户 rather than the sizer, from shrinking the window too far. 而不是大小调整器,因为将窗口缩小得太远了。

The way to do that is to handle the resize event. 这样做的方法是处理resize事件。 In the handler check the new size against the minimum size, and if it is too small, than do not allow the resize to occurr. 在处理程序中,对照最小尺寸检查新尺寸,如果尺寸过小,则不允许重新调整尺寸。

Sizers distribute the available size among their elements. 大小调整器在其元素之间分配可用大小。 If there is not enough space available, something bad will inevitably happen, ie at least some controls will not have enough size. 如果没有足够的可用空间,将不可避免地发生不良情况,即,至少某些控件的大小将不足。

To prevent this from happening you must ensure that the top level window is big enough initially and can't be resized by the user to a smaller size. 为防止这种情况发生,您必须确保顶层窗口最初足够大,并且不能由用户将其调整为较小的大小。 The easiest way to achieve it is to call SetSizerAndFit(sizer) when associating the sizer with the top level window. 实现此目标的最简单方法是将sizer与顶层窗口相关联时调用SetSizerAndFit(sizer) This will do both of these things at once. 这将同时完成这两项操作。

OK eventualy I got the answer. 好的,最终我得到了答案。 The sizer that is attached to the frame must call SetSizeHints() 附加到框架的sizer必须调用SetSizeHints()

EDIT : It is correct to call it for the top level window, as suggested below. 编辑:如下所示,为顶层窗口调用它是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM