MessageBox Size

How does the .NET MessageBox determine its size relative to the resolution of the screen on which it is displayed?

I am writing a slightly more flexible dialog box for a WPF application. The location of the window is laid out in the 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 remove x elements from the list. Then the items are listed in the confirmation dialog box. If there are many (say, 50+) elements, the window can become large - too large for my taste.

What I need is a function that defines the MaxHeight and MaxWidth dialog box on the current screen in a way that mimics the Microsoft MessageBox dialog box.

PS: I call 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 the dialog will be displayed, the screen on which the MessageDialog Owner window is located is displayed. The first (main) screen is used as a backup.

+6
source share
1 answer

You will not find anything similar to the documented one, however, according to Raymond in Windows Vista, the message window algorithm determined the width by choosing the smallest of the following values, as a result of which a field appears that fits into the workspace:

  • Width of the longest line
  • 278 DLU ( Dialogue Blocks )
  • 5/8 workspace width
  • 3/4 workspace width
  • 7/8 workspace width

(I interpreted this as meaning that (for example) the width will be 5/8 of the width of the workspace, unless it leads to a dialog that is higher than the height of the workspace, in which case it will use a wider width).

That should at least give you some pointers to choosing the maximum width that doesn't look out of place.

As far as I know, the message box does not have a maximum height, but I think that such an algorithm will work well.

If your dialogue is really very large, you may just need to make the dialog mutable / maximized. (I am not a fan of dialog boxes that display lists that are too large, but do not allow you to resize the dialog box to a more suitable size).

+6
source

Source: https://habr.com/ru/post/894373/


All Articles