2009-12-26 51 views

回答

3

就在您调用SmtpClient.SendAsync()之前,将ProgressBar.Visible属性设置为True。在SmtpClient.SendCompleted事件的事件处理程序中将其设置为False。 PB必须将其Style属性设置为“选取框”。

您不能以其他方式给出准确的进度信息,StmpClient和MailMessage类都没有一个事件告诉您工作完成了多少。

0

您可以使用计时器控件并使进度条在处理程序中移动。当达到最大值时,您可以将进度条重置为零。这不会反映实际的进度,但它会让用户看到并显示应用程序未被锁定。

2

只是把这个代码,您SMPT客户端代码每个步骤之后和每个步骤后增加值,

progressbar1.value = 10 

下面代码可以帮助你..

包含: 3文本框(TB_subject, TB_name,TB_cmt) 1个按钮(btn_submit) 1个进度条(Progressbar1) 和 3个标签。

例如: -

代码:

Imports System.Net.Mail 
____________________________________________________________________ 
Public Class Form1 

Private Sub btn_submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_submit.Click 
If TB_Name.Text = "" Or TB_Subject.Text = "" Or TB_Cmt.Text = "" Then 
MsgBox("Name, Subject and Comment are required fields", vbCritical, "Error") 

Else 



Try 
Dim Mail As New MailMessage 
progressbar1.value = 10   'note that the value is "10" 

Mail.From = New MailAddress("[email protected]") 
progressbar1.value = 20      'now its "20" 

Mail.To.Add("[email protected]") 
progressbar1.value = 30      '"30" and its increases..... 

Mail.Subject = TB_Subject.Text & " - " & TB_Name.Text 
progressbar1.value = 40 

Mail.Body = TB_Cmt.Text 
progressbar1.value = 50 

Dim smtp As New SmtpClient("smtp.gmail.com") 
progressbar1.value = 60 

smtp.Port = 587 
progressbar1.value = 70 

smtp.EnableSsl = True 
progressbar1.value = 80 

smtp.Credentials = New System.Net.NetworkCredential("YOUR GMAIL USERNAME ID HERE", "YOUR GMAIL PASSWORD HERE") 
progressbar1.value = 90 

smtp.Send(Mail) 
progressbar1.value = 100 


MsgBox("Sent Successfully", vbInformation, "Thank you") 
progressbar1.value = 0     'Reset Progress Bar. 

Catch ex As Exception 
MsgBox("There was an error, the program will close now!!", vbCritical, "Fatal error") 
End Try 
End If 
End Sub