Solved

Close Messagebox

Posted on 2014-01-15
5
294 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
[X]
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
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:James Atkin
James Atkin 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

627 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