How to 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

Bold text in MessageBox

It is possible, a message box is a regular window that can be messed with like any other. The code to do so is however a bit gritty. 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 BoldMessageBox : IDisposable { private … Read more

Show message Box in .net console application

We can show a message box in a console application. But first include this reference in your vb.net or c# console application System.Windows.Forms; Reference: To add reference in vb.net program right click (in solution explorer) on your project name-> then add reference-> then .Net-> then select System.Windows.Forms. To add reference in c# program right click … Read more

center MessageBox in parent form [duplicate]

I really needed this in C# and found Center MessageBox C#. Here’s a nicely formatted version using System; using System.Windows.Forms; using System.Text; using System.Drawing; using System.Runtime.InteropServices; public class MessageBoxEx { private static IWin32Window _owner; private static HookProc _hookProc; private static IntPtr _hHook; public static DialogResult Show(string text) { Initialize(); return MessageBox.Show(text); } public static DialogResult … Read more

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

MessageBox with YesNoCancel – No & Cancel triggers same event

This should work fine: Dim result As DialogResult = MessageBox.Show(“message”, “caption”, MessageBoxButtons.YesNoCancel) If result = DialogResult.Cancel Then MessageBox.Show(“Cancel pressed”) ElseIf result = DialogResult.No Then MessageBox.Show(“No pressed”) ElseIf result = DialogResult.Yes Then MessageBox.Show(“Yes pressed”) End If

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