Msgbox automatically disappears after a certain time

Is there any type of msgbox in vb.net that displays a message and automatically disappears after a certain time? Or is there any way to hide msgbox without clicking OK?

+8
source share
8 answers

you can use

CreateObject ("WScript.Shell"). Popup (Welcome, 1, Title)

this msgbox will close automatically after 1 second

+9
source

No, I don’t think there is a built-in structure control that will do this for you. However, you can easily do this with a special form that starts the Load timer in it. Then, when the set amount of time has passed, in the Elapsed timer event, you can simply close the form.

+3
source

Use a timer or some type of delay / sleep and after the running time

 SendKeys.Send("~") 

This is the same as pressing the ENTER key.

You may need to start it by activating the msgbox window again.

+1
source

Inspired by the answers, this is what I came up with, working perfectly in simple cases, allowing you to directly use all the features of MsgBox:

 Imports System.Threading Module FormUtils Private sAutoClosed As Boolean Private Sub CloseMsgBoxDelay(ByVal data As Object) System.Threading.Thread.Sleep(CInt(data)) SendKeys.SendWait("~") sAutoClosed = True End Sub Public Function MsgBoxDelayClose(prompt As Object, ByVal delay As Integer, Optional delayedResult As MsgBoxResult = MsgBoxResult.Ok, Optional buttons As MsgBoxStyle = MsgBoxStyle.ApplicationModal, Optional title As Object = Nothing) As MsgBoxResult Dim t As Thread If delay > 0 Then sAutoClosed = False t = New Thread(AddressOf CloseMsgBoxDelay) t.Start(delay) MsgBoxDelayClose = MsgBox(prompt, buttons, title) If sAutoClosed Then MsgBoxDelayClose = delayedResult Else t.Abort() End If Else MsgBoxDelayClose = MsgBox(prompt, buttons, title) End If End Function End Module 

PS: you should add this to yourApp.config file:

<appSettings> <add key="SendKeys" value="SendInput"/> </appSettings>

+1
source

I don’t think there is such a tool. But I think you can do it by following these steps:

  • Create an instance of the Form element and create it as a mailbox.
  • In the form load event, get the system time or start the timer at intervals.
  • This timer will note how many seconds you want, then raise the Form Close event.

PS: If I'm wrong, sorry. I'm just trying to solve something, maybe there is a better way to solve your problem.

0
source

You can do this by adding a timer to your form. "Timer for auto-wipe after 100 ms Dim seconds As Integer = 100

 'Existing code.... Timer1.Start() MessageBox.Show("Window Timed Out", "TimeOut") Me.Close() 'Tick Event Code Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick seconds = seconds - 1 If seconds < 1 Then` Me.Close() End If End Sub 
0
source

I have a code to show the file update time and close the message box for 3 seconds. Please see below. I hope this code can support this topic.

  Sub Workbook_Open() Application.ScreenUpdating = False SplashUserForm.Show Windows(ThisWorkbook.Name).Visible = True Application.ScreenUpdating = True last_update = "Last updated : " & Format(FileDateTime(ThisWorkbook.FullName), "ddd dd/mm/yy hh:mm ampm") 'Close message after time if no action! Dim myTimedBox As Object Dim boxTime%, myExpired%, myOK%, myQuestBox% 'Access timed message box. Set myTimedBox = CreateObject("WScript.Shell") boxTime = 3 'User Selected "OK." If myQuestBox = 1 Then 'Add any code in place of code below for this condition! myOK = myTimedBox.Popup(last_update & vbCr & "Do nothing and this message will close in 3 seconds.", _ boxTime, "You Took Action!", vbOKOnly) Else 'User took no Action! myExpired = myTimedBox.Popup(last_update & vbCr & "Do nothing and this message will close in 3 seconds.", _ boxTime, "No Action Taken!", vbOKOnly) End If End Sub 
0
source
-one
source

All Articles