1

Can someone give a clear example of setting the timeout feature in the MessageBoxManager class?

I saw these links but couldn't understnad how to use it properly. I need to envoke a messagebox asking something and it will count down 3 seconds for a default answer. http://www.codeproject.com/Articles/13123/MessageBoxManager-A-Windows-Forms-component-that-p

http://www.codeproject.com/Articles/18399/Localizing-System-MessageBox

I tried using this:

MessageBoxManager.Yes = "Lab";
MessageBoxManager.No = "Machine";
MessageBoxManager.Register();

DialogResult dialogResult = MessageBox.Show("Choose your working method",
  "Choose your working method", MessageBoxButtons.YesNo);

But there isn't any way to choose the timeout feature...

Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
roy.me
  • 421
  • 2
  • 7
  • 19
  • Look at their Demo Code, they declare an Instance of the class. `MessageBoxManager mbm = new MessageBoxManager();` – Mark Hall Dec 23 '14 at 15:22
  • I tried that. I guess I'm missing something here, as the only things I can choose from are: 'Equals','GetHashCode','GetType','ToString'. When I open their project it doesn't work either, it gives error saying the 'Error 10 'System.Windows.Forms.MessageBoxManager' does not contain a definition for 'CustomIcon' and no extension method 'CustomIcon', for example... – roy.me Dec 23 '14 at 15:26
  • make sure you also enable the Hook. `mbm.HookEnabled = true;` – Mark Hall Dec 23 '14 at 15:28
  • I don't get any options to choose from when I click "mbm." besides 'Equals','GetHashCode','GetType','ToString'. – roy.me Dec 23 '14 at 15:30

2 Answers2

3

try the following using the DLL in the first link. Note that the library in the first link is totally different from that in the second link.

MessageBoxManager manager = new MessageBoxManager();
manager.ShowTitleCountDown = true;
manager.AutoCloseResult = System.Windows.Forms.DialogResult.No;
manager.TimeOut = 5;
manager.AutoClose = true;
manager.HookEnabled = true;
DialogResult res = MessageBox.Show("Testing", "Hello", MessageBoxButtons.YesNo);

if (res == System.Windows.Forms.DialogResult.Yes)
{
    Console.WriteLine("yes pressed");
}
else
{
    Console.WriteLine("no presssd");
}
Oday Fraiwan
  • 1,147
  • 1
  • 9
  • 21
  • Ok! This indeed seems to solve the problem. When I added the MessageBoxHook.dll instead of MessageBoxManager.dll I could saw all options. Nevertheless, when I try to debug and launch the app I get an error saying: "Could not load file or assembly 'MessageBoxHook, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format." any idea?. I made a reference thru the Solution Explorer->Reference->Add Reference. – roy.me Dec 24 '14 at 11:12
  • Please note that the two classes in the two links have the same name but different namespace. You can download the source code and modify the name of one of the two classes. That may cause this problem. Try delete the reference and add it again. – Oday Fraiwan Dec 24 '14 at 15:09
1

This should help you.

Close a MessageBox after several seconds

Or if you really want to use MessageBoxManager you could set the following properties:

int TimeOut : This specifies the time-out in seconds that is used by the auto-close, button-disable, and title-countdown features.

bool AutoClose : Set this to true to close the message-box automatically after the number of seconds specified by the TimeOut property has elapsed.

DialogResult AutoCloseResult : When the AutoClose property is set, you can specify a DialogResult via this property that will be seen by the calling code (that invoked the message-box).

Community
  • 1
  • 1
GlobalJim
  • 1,149
  • 2
  • 16
  • 24
  • Thanks, but can you please explain how do I use the Timeout in the code? This part I do not understand. I'm a bit of a newbie... – roy.me Dec 23 '14 at 15:00
  • MessageBoxManager.TimeOut = 3; MessageBoxManager.AutoClose = true; MessageBoxManager.AutoCloseResult = DialogResult.Yes; – GlobalJim Dec 23 '14 at 15:08
  • Well, this is the first thing I've tried, but unfortunately it doesn't work. Only objects beneath the class are 'abort','cancel','yes','no', etc... this is why I've asked my question. – roy.me Dec 23 '14 at 15:15
  • Did you create an instance of the class? Those properties might not be static. MessageBoxManager mbm = new MessageBoxManager(); mbm.TimeOut = 3; etc... – GlobalJim Dec 23 '14 at 15:17
  • Any error messages? Could you find the properties? is `HookEnabled` set to true? – GlobalJim Dec 23 '14 at 15:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/67556/discussion-between-roy-me-and-globaljim). – roy.me Dec 23 '14 at 15:58