Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Close Messagebox

Posted on 2014-01-15
5
Medium Priority
?
297 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 1000 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 1000 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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
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…

722 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