.NET的MessageBox如何确定其相对于所显示屏幕的分辨率的大小?
我正在为WPF应用程序编写一个稍微灵活一些的对话框窗口。窗口的布局被放置在网格中:
+-----------------
| auto: Header // A header for the dialog.
+-----------------
| auto: Content // can be any FrameworkElement.
+-----------------
| auto: BottomPanel // With buttons <OK>, <Cancel>, <Delete>, etc.
+-----------------Content细胞可能非常大。在我的一个用例中,用户希望从列表中删除x元素。然后在确认对话框中列出这些元素。如果有很多(比如50+)元素,那么窗口就会变大--对我的口味来说太大了。
我想要的是一个从当前屏幕上确定对话框窗口的MaxHeight和MaxWidth属性的函数,它可以模仿微软自己的MessageBox对话框。
PS:我使用以下static方法调用消息对话框:
// MessageDialog class
public static object Show(
Window owner,
FrameworkElement content,
string title,
string header,
params MessageDialogButton[] buttons
);
/* The MessageDialogButton class has the following properties:
* Text, ReturnValue, IsDefault, IsCancel. The class produces
* System.Windows.Controls.Button objects that when clicked
* return the value of their ReturnValue property--which is then
* returned by MessageDialog::Show(...)
*/PPS:要确定显示对话框的屏幕,MessageDialog窗口的Owner所在的屏幕。作为后盾,使用第一个(主)屏幕。
发布于 2011-08-05 11:44:15
您不会发现任何文档中的内容,但是Windows中的雷蒙德消息框算法通过选择最小的消息框来确定消息框的宽度,从而得到一个适合工作区域的框:
(我的解释是,这意味着(例如)宽度将是工作区宽度的5/8,除非这样导致的对话框比工作区的高度高,在这种情况下,它将使用更宽的宽度)。
这至少应该给你一些指点来选择一个不显得不太合适的最大宽度。
据我所知,消息框没有最大高度,但我认为类似的算法会很好地工作。
如果您的对话框确实很大,那么您可能需要考虑使该对话框可调整大小/最大化。(我不喜欢显示列表太大但不允许您将对话框调整到更合适大小的对话框)。
https://stackoverflow.com/questions/6955465
复制相似问题