.NET如何MessageBox确定其相对于显示它的屏幕分辨率的大小?
我正在为WPF应用程序编写一个稍微灵活的对话窗口.窗口的布局布局在网格中:
+-----------------
| auto: Header // A header for the dialog.
+-----------------
| auto: Content // can be any FrameworkElement.
+-----------------
| auto: BottomPanel // With buttons <OK>, <Cancel>, <Delete>, etc.
+-----------------
Run Code Online (Sandbox Code Playgroud)
该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(...)
*/
Run Code Online (Sandbox Code Playgroud)
PPS:确定显示对话框的屏幕,MessageDialog窗口所在的屏幕Owner.作为后备,使用第一(主)屏幕.
你不会发现任何类似的记录,但是根据 Windows Vista中的Raymond,消息框算法通过选择以下最小的一个来确定消息框的宽度,从而产生一个适合工作区域的框:
(我把这意味着(例如)宽度将是工作区宽度的5/8,除非这导致对话框高于工作区的高度,在这种情况下它将使用更宽的宽度).
这至少应该为您提供一些选择最大宽度的指针,这些宽度看起来不合适.
据我所知,消息框没有最大高度,但我想类似的算法可以很好地工作.
如果您的对话框确实非常大,那么您可能需要考虑使对话框可调整大小/最大化.(我不喜欢显示太大的列表但不允许您将对话框调整为更合适大小的对话框的粉丝).
| 归档时间: |
|
| 查看次数: |
11878 次 |
| 最近记录: |