RKh
RKh

Reputation: 14159

How to auto hide message box?

I want a timer type of property for message boxes. After displaying error, it must disappear without user intervention after 5 seconds.

Upvotes: 5

Views: 14849

Answers (5)

bcosca
bcosca

Reputation: 17555

timer.Interval=5000;
timer.Enabled=true;
MessageBox.Show("Should close automatically");

Associate the following snippet with the timer's Tick eventhandler:

private void timer_Tick(object sender,EventArgs evt) {
    timer.Enabled=false;
    SendKeys.Send("{ESC}"); // SendWait as alternative
}

Upvotes: 9

DOK
DOK

Reputation: 32851

If this is on a web page, you can use javascript or jQuery for a quite nice effect. This is often referred to as "fade" animation. It does use a timer.

With this approach, you wouldn't use an actual alert or MessageBox. You use a <div> or some other named HTML element.

You can find the code here for what you're doing using javascript.

Or if you're using jQuery, look up fadeOut. Here's one article.

Upvotes: 0

johnny
johnny

Reputation: 19755

What about using sendkeys?

Something like this:

http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx

at least to get you started in research.

Upvotes: 1

David Heffernan
David Heffernan

Reputation: 613602

A message box is the wrong solution. You need a hint window.

Upvotes: 0

BeemerGuy
BeemerGuy

Reputation: 8279

Not possible with the MessageBox class; you have to create your own form that mimics it and add this feature yourself.

Upvotes: 2

Related Questions