How have you successfully implemented MessageBox.Show() functionality in MVVM?

Services to the rescue. Using Onyx (disclaimer, I’m the author) this is as easy as: public void Foo() { IDisplayMessage dm = this.View.GetService<IDisplayMessage>(); dm.Show(“Hello, world!”); } In a running application, this will indirectly call MessageBox.Show(“Hello, world!”). When testing, the IDisplayMessage service can be mocked and provided to the ViewModel to do what ever you want … Read more

Clickable URL in a Winform Message Box?

One option is display the url in the message box, along with a message and provide the help button that takes you to that url: MessageBox.Show( “test message”, “caption”, MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, 0, ‘0 is default otherwise use MessageBoxOptions Enum “http://google.com”, “keyword”) Important to note this code cannot be in the load event of the … Read more

WPF MessageBox window style

According to this page, WPF picks up the old styles for some of the controls. To get rid of it, you have to create a custom app.manifest file (Add -> New item -> Application Manifest File) and paste the following code in it (right after the /trustInfo – Tag ): <!– Activate Windows Common Controls … Read more

Close a MessageBox after several seconds

Try the following approach: AutoClosingMessageBox.Show(“Text”, “Caption”, 1000); Where the AutoClosingMessageBox class implemented as following: public class AutoClosingMessageBox { System.Threading.Timer _timeoutTimer; string _caption; AutoClosingMessageBox(string text, string caption, int timeout) { _caption = caption; _timeoutTimer = new System.Threading.Timer(OnTimerElapsed, null, timeout, System.Threading.Timeout.Infinite); using(_timeoutTimer) MessageBox.Show(text, caption); } public static void Show(string text, string caption, int timeout) { new AutoClosingMessageBox(text, … Read more

Winforms-How can I make MessageBox appear centered on MainForm?

It is possible with some servings of P/Invoke and the magic provided by Control.BeginInvoke(). Add a new class to your project and paste this code: using System; using System.Text; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; class CenterWinDialog : IDisposable { private int mTries = 0; private Form mOwner; public CenterWinDialog(Form owner) { mOwner = owner; … Read more