does anyone know how to close a messagebox automatically?
(without the using clicking it)
Printable View
does anyone know how to close a messagebox automatically?
(without the using clicking it)
You need some sort of subclassing , but why don't you take the easier path and make your own custom message box with a timer .
Pirate - thanks for the reply.
I can't use a timer - as
a) I don't know how long to display the messagebox before closing it.
b) I wish to retrospectively incorporate the functionality into the application and so would rather not create my own messagebox class at this point (although I like your thinking).
Effectively what I am doing is recognising that the application hasbn't been used for a given amount of time and displaying a user password screen - however if the user changes I need to close all the children (and other modally displayed) forms.
This is fine I can do this - however I also wish to close down any messageboxes. The problem I have is that when I close the form that requested the messagebox - the messagebox terminates with a "No" (even if it only has a Cancel and Yes button). Mostly this is ok - but It can give unexpected results (such as aborting) depending on the code that follows the messagebox.
You could have a class with a shared Public flag:
e.g.
Public Class SomeClass
Public Shared ApplicationIsTerminating() as Boolean
End class
and when your application is being closed (or your forms are being closed) set SomeClass.ApplicationIsTerminating = True
When you show a messagbox, use something like the following:
Dim msgboxResult As Windows.Forms.DialogResult = Windows.Forms.MessageBox.Show("Your message", "Your caption", MessageBoxButtons.OKCancel)
If Not SomeClass.ApplicationIsTerminating Then
If msgboxResult = DialogResult.OK Then
' OK processing
ElseIf msgboxResult = DialogResult.Cancel Then
' Cancel processing
End If
Else
'Take a different course of action
End If
hmm lets see... wanna try this?
make a sub that would call the messagebox. Call that sub by declaring a new thread... try terminating the thread and see if the messagebox closes
yes that'll work.
Thanks Mr. Polite. I knew there would be some lateral thinking in there somewhere.
Of course you could always make your own Messagebox form and have full controll over it.
yeah that;s cool too. Edneeis had an example how to make a form and call it like a messagebox (so it would return the selected value and stuff like that). you may find it if you searchQuote:
Originally posted by Cander
Of course you could always make your own Messagebox form and have full controll over it.