question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`MessageBox.Show` overload with `StartPosition` parameter

See original GitHub issue

Background and motivation

When Messagebox.Show is called, often it will be associated to an open window. The messagebox will show in the middle of the monitor. This is not really user friendly when the user has a large monitor or when using non-maximized forms.

Example of users working around the problem: https://stackoverflow.com/questions/1732443/center-messagebox-in-parent-form

API Proposal

namespace System.Windows.Forms;

public enum MessageBoxStartPosition
{
Default = 0,
CenterScreen = 1,
CenterParent = 2
}

public static DialogResult Show(
            string? text,
            string? caption,
            MessageBoxButtons buttons,
            MessageBoxIcon icon,
            MessageBoxDefaultButton defaultButton,
            MessageBoxOptions options,
            MessageBoxStartPosition startPosition)

API Usage

MessageBox.Show("Test Message box text","Test Caption", 
MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxStartPosition.CenterParent)

Alternative Designs

No response

Risks

No response

Will this feature affect UI controls?

No.

Issue Analytics

  • State:closed
  • Created 5 months ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
RussKiecommented, Apr 28, 2023

Something like this should work:

// code
ShowMessage(owner, message, heading);


// 
private static void ShowMessage(I32Window owner, string message, string heading)
{
#if NET5_OR_GREATER
     MessageBox.Show(owner, message, heading);
#else
     TaskDialogPage page = new(...);
     TaskDiaglog.Show(owner, page);
#endif
}
2reactions
RussKiecommented, Apr 28, 2023

I agree that TD is a bit more verbose, but it’s also feature-ruch and (which is important) it is test-friendly. Migrating from MB to TD isn’t that difficult, one can add a quick helper method that would translate MB calls to comparable TD calls.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MessageBox.Show Method (System.Windows.Forms)
Displays a message box in front of the specified object and with the specified text, caption, buttons, icon, default button, and options. Show(String,...
Read more >
Why does my MessageBox.Show generate an error about ...
1 and 2) MessageBox doesn't have an overload for (string, MessageBoxButtons). ... Show(string, string)' has some invalid arguments.
Read more >
Position a Windows Forms MessageBox in C# - CodeProject
There's no method in C# to position a MessageBox . But in C++, you can position a message box by finding the message...
Read more >
WinForms MessageBox.Show Examples
Show method calls is important. The compiler applies overload resolution to call the best method in the method group.
Read more >
Messagebox Location C
How to display Message Box in Android Using Xamarin C#. Pfad und Name der Hilfedatei, ... How to set a custom position for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found