消息框大小
.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 个)元素,窗口可能会变得很大——对于我的口味来说太大了。
我想要一个函数,以模仿微软自己的 MessageBox 的方式确定当前屏幕上对话框窗口的 MaxHeight 和 MaxWidth 属性>对话框。
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
窗口的屏幕所有者
位于。作为后备,使用第一个(主)屏幕。
How does .NET's MessageBox
determine its size relative to the resolution of the screen on which it is displayed?
I am writing a slightly more flexible dialog window for a WPF application. The layout of the window is layed out in a Grid:
+-----------------
| auto: Header // A header for the dialog.
+-----------------
| auto: Content // can be any FrameworkElement.
+-----------------
| auto: BottomPanel // With buttons <OK>, <Cancel>, <Delete>, etc.
+-----------------
The Content
cell can be VERY large. In one of my use cases, the user wants to delete x elements from a list. The elements are then listed in the confirmation dialog. If there are many (let's say 50+) elements, the window can get large—too large for my taste.
What I would like is a function that determines the MaxHeight
and MaxWidth
properties of the dialog window from the current screen in a way that mimics Microsoft's own MessageBox
dialog.
PS: I invoke the message dialog with the following static
method:
// 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: To determine the screen on which to display the dialog, the screen on which the MessageDialog
window's Owner
is located. As a fallback, the first (primary) screen is used.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不会找到类似的记录,但是 根据雷蒙德(过时的链接,这个链接更新)在 Windows Vista 中,消息框算法确定宽度消息框的宽度,选择以下最小的一个,从而产生一个适合工作区域的框:
(我解释为这意味着(例如)宽度将为工作区域宽度的 5/8,除非这导致对话框高于工作区域的高度,在这种情况下它将使用更宽的宽度)。
这至少应该为您提供一些关于选择看起来不合适的最大宽度的指导。
据我所知,消息框没有最大高度,但我想类似的算法会很好地工作。
如果您的对话框确实非常大,那么您可能需要考虑使对话框可调整大小/最大化。 (我不喜欢显示太大列表但又不允许您将对话框调整为更合适大小的对话框)。
You aren't going to find anything like that documented, however according to Raymond (outdated link, this link is more recent) in Windows Vista the message box algorithm determined the width of the message box by choosing the smallest of the following which resulted in a box that fits in the working area:
(I interpred this to mean that (for example) the width will be 5/8th of the width of the working area unless this results in the dialog which is taller than the height of the working area, in which case it will use a wider width).
This should at least give you some pointers for choosing a maximum width that doesn't look out of place.
As far as I am aware the message box doesn't have a maximum height, but I imagine a similar algorithm would work nicely.
If your dialog genuinely is very large then you might want to consider just making the dialog resizable / maximizable. (I'm not a fan of dialogs that display lists that are too large but don't allow you to resize the dialog to a more suitable size).