close automatically a form

D

dotnetter

Straight forward action though ... I tkink it's not. I create a form
(as a custom messagebox) with just one label on it. Using
System.Threading.Thread.Sleep(3000) does the job but the label text is
not shown during these 3 seconds. After the Sleep instruction the label
text is shown but is unreadable since I close the form after the
"sleep". Using the "Sleep" method during the Closing Event of the form
(and thus not in the function used) doesn't solve the problem. Any
ideas ?

This is the code used:

Private Function ShowSuccessMessageBox()
Dim message As String
Dim w As Int16
Dim h As Int16

fMsgbox = New Form
lblMessage = New Label

message = "Email and possible attachments successfully saved."
w = message.Length

With lblMessage
.BackColor = Color.Green
.ForeColor = Color.White
.Font = New Font("Arial", 10, FontStyle.Bold)
.Location = New Point(15, 25)
.Width = w * 7
.Text = message.ToString
End With

w = 375
h = 100
With fMsgbox
.Controls.Add(lblMessage)
.CausesValidation = False
.StartPosition = FormStartPosition.CenterScreen
.BackColor = System.Drawing.Color.Green
.MinimumSize = New System.Drawing.Size(w, h)
.MaximumSize = New System.Drawing.Size(w, h)
.MinimizeBox = False
.MaximizeBox = False
.Text = "Successful Save"
.Show()
End With
System.Threading.Thread.Sleep(3000)
fMsgbox.Close()
fMsgbox = Nothing
End Function
 
R

R. MacDonald

Hello, DotNetter,

Try adding:

Application.DoEvents()

directly before:

System.Threading.Thread.Sleep(3000)

Cheers,
Randy
 
D

dotnetter

So simple but also very effective. It works just fine. Thanks a lot for
this solution.

Dirk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top