.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多个)元素,那么窗口可能会变得太大 - 对我来说太大了。
我想要的是一个函数,它以模仿Microsoft自己的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
所在的屏幕。作为后备,使用第一个(主要)屏幕。
答案 0 :(得分:7)
你不会发现任何类似记录的内容,但是在Windows Vista中according to Raymond消息框算法通过选择以下最小值来确定消息框的宽度,从而产生适合的框。工作区域:
(我认为这意味着(例如)宽度将是工作区宽度的5/8,除非这会导致对话框高于工作区的高度,在这种情况下它会使用更宽的宽度。)
这至少应该为您提供一些选择最大宽度的指针。
据我所知,消息框没有最大高度,但我认为类似的算法可以很好地工作。
如果您的对话框确实非常大,那么您可能需要考虑使对话框可调整大小/最大化。 (我不喜欢那些显示太大但不允许你将对话框调整到更合适尺寸的列表的对话框。)