Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of MessageBox

Tags:

c#

wpf

messagebox

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 Contentcell 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 MaxHeightand MaxWidthproperties of the dialog window from the current screen in a way that mimics Microsoft's own MessageBoxdialog.

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.

like image 938
Minustar Avatar asked Aug 05 '11 11:08

Minustar


People also ask

How do I increase the size of the MessageBox in VBA?

Simply you can't. The message box is a system component and the size increase with the contents (text, icons and buttons) in it. Your only solution is to create your own messagebox control.

What is MessageBox C#?

MessageBox is a class in C# and Show is a method that displays a message in a small window in the center of the Form. MessageBox is used to provide confirmations of a task being done or to provide warnings before a task is done. Create a Windows Forms app in Visual Studio and add a button on it.

How do I change the size of a text box in Python?

By Changing ReadMe Filetxt the length of the content of the readme file determines the size of the messagebox.


1 Answers

You aren't going to find anything like that documented, however according to Raymond 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:

  • The width of the longest line
  • 278 DLU (Dialog units)
  • 5/8 of the width of the working area
  • 3/4 of the width of the working area
  • 7/8 of the width of 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).

like image 67
Justin Avatar answered Oct 13 '22 07:10

Justin