sirimit
asked on
I want to close message box auto. Thank you.
I want to close message box auto. Sum error I'm show alert message box for user if user not click OK. It auto close in 10 second. Thank you very much.
Here is example sourcecode http://www.codeproject.com/KB/dialog/AutoCloseMessageBox.aspx
ASKER
I want example code style vb not C thank you very much.
Here's a easy example using SendKey() method
Private tm As New Timer
Sub tmTick(ByVal sender As Object, ByVal e As System.EventArgs)
tm.Stop()
SendKeys.Send("{ENTER}")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
tm.Interval = 10000
AddHandler tm.Tick, AddressOf tmTick
tm.Start()
MessageBox.Show("This msg will close in 10 seconds!")
End Sub
You can rewrite it to vb.net, just change syntax. But maybe i can suggest you to create your own msgbox form. Just create form and style it like msg box. For showing it you can override show or better ShowDialog function (i put example into code). Then put there one timer and to it me.close(). You can for example also add countdown to autoclose.
With this solution you can better customize msgbox to fit your requirements.
With this solution you can better customize msgbox to fit your requirements.
Public Overloads Function ShowDialog(ByRef text As string, ByRef buttons As integer, ByRef icon As integer, ByRef timeToEnd as integer) As Windows.Forms.DialogResult
'here put code for fill requested data in form
'here you can call timer1 to close dialogbox
Timer1.Interval = timeToEnd
Timer1.Enabled = Enabled
'load up order defaults
Return MyBase.ShowDialog()
End Function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Close()
End Sub
I also think about send key, but that is not good solution. If app display msgbox to user and user for example switch window to for example msn chat and start writing to someone, after 10 seconds application in background send enter but that enter will be handled with application which has focus, so for example with msn, app automaticali send message :).
This "Timer1.Enabled = Enabled" should be "Timer1.Enabled = True" of course :). Sorry :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sirimit: as i wrote, solution with send keys is not good, it has lot of possibilities to dont work.
ASKER
Hello all,
Thank you for answer. I'm test all solution. Webtubbs 's best solution. Now I use Webtubbs 's solution.
Thank you much for all.
Thank you for answer. I'm test all solution. Webtubbs 's best solution. Now I use Webtubbs 's solution.
Thank you much for all.
>>Webtubbs 's best solution. Now I use Webtubbs 's solution.
So why did you accept another comment???
So why did you accept another comment???
>> So why did you accept another comment???
Totally agree :)
You could split al least or accept Wayne comment.
Totally agree :)
You could split al least or accept Wayne comment.
ASKER
How to cancel accept solution ? I want to change it but I don't know how to. Sorry webtubbs. I'm click Not your solution is not thing.