Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Close Messagebox

Posted on 2014-01-15
5
291 Views
Last Modified: 2014-01-29
In Windows applications, is there a way to close a messagebox within certain amount of time?

Try
      'my code

catch

      messagebox.show("Error")  << I want this messagebox to be closed after an hour

end
0
Comment
Question by:VBdotnet2005
5 Comments
 
LVL 14

Expert Comment

by:quizwedge
ID: 39782888
You'll need to use threading and a timer. There are a few examples at  http://www.vbforums.com/showthread.php?605979-self-closing-message-box&s=d05590a61b90627b83e96207c9cf069e&p=3745046#post3745046

The idea is that call New Threading.Thread(AddressOf closeMsgBox) where closeMsgBox is a function that sends keyboard events to close the MsgBox.

The closeMsgBox code from the site above is

Private Sub closeMsgbox(ByVal delay As Object)
        Threading.Thread.Sleep(CInt(delay) * 1000)
        AppActivate(Me.Text)
        keybd_event(VK_RETURN, 0, KEYEVENTF_KEYDOWN, 0)
        keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0)
    End Sub

Open in new window

0
 
LVL 40
ID: 39782897
MessageBox is a modal or dialog window and requires user intervention.

Not a good one. You could use a SendKeys command to send keys to the keyboard processor, and thus simulate user interaction, but it is always dangerous to do because you cannot control which application will receive the keys. After an hour, you can almost be sure that another application will have the focus and will get the keys, which might cause problems in that application.

The only good way to do it is to display a form that you created and set a timer to close it.
0
 
LVL 14

Accepted Solution

by:
quizwedge earned 250 total points
ID: 39783062
I missed that you wanted it to close after an hour. Custom form is the best way to go. Another option would be to have the timer give your app focus, but you still risk annoying the user because they're in the middle of typing something.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39783076
0
 
LVL 4

Assisted Solution

by:jatkin
jatkin earned 250 total points
ID: 39784638
Hi,

I have used this in the past - seemed to work well:

http://www.codeproject.com/Articles/7968/MessageBox-with-a-timeout-for-NET

Hope this helps,

James
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question