Solved

Close Messagebox

Posted on 2014-01-15
5
288 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 69

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now