عندى مشكلة صغيره مشكلة تعليق الفورم اثناء التحميل عدلت على الكود لاستخدام Events و محاولة التخلص من التعليق لاكن لم ينجح الامر
lمع العلم اذا استخدمة client.DownloadFileAsync الفورم يعمل لاكن الصور لا تعمل !
كود :
Dim wb As New WebBrowser With {.ScriptErrorsSuppressed = False}
Dim WithEvents wc As New Net.WebClient()
Private url As String = "http://downloadinfo.html-5.me/Profile/"
Private htmlSource As String
Private cookie As String
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
wb.Navigate(url)
AddHandler wb.DocumentCompleted, AddressOf wb_DocumentCompleted
End Sub
Private Sub wb_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
cookie = sender.Document.Cookie
wc.Headers.Add(Net.HttpRequestHeader.Cookie, cookie)
htmlSource = wc.DownloadString(url)
Dim Matches As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(htmlSource, "(?<=href="").+?(?="")")
If Not IO.Directory.Exists("Images") Then IO.Directory.CreateDirectory("Images")
For Each s As System.Text.RegularExpressions.Match In Matches
If s.Value.EndsWith(".png") Then
Dim filename As String = If(s.Value.StartsWith("http"), s.Value, url & s.Value)
Dim d() As Byte = wc.DownloadData(filename)
Image.FromStream(New IO.MemoryStream(TryCast(d, Array))).Save("Images\" & IO.Path.GetFileName(filename))
End If
Next
End Sub
Private Sub wc_downlooadprogresschange(sender As Object, e As DownloadProgressChangedEventArgs) Handles wc.DownloadProgressChanged
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub wc_DownloadDataCompleted(sender As Object, e As DownloadDataCompletedEventArgs) Handles wc.DownloadDataCompleted
MsgBox("تم الحفظ")
Button1.Enabled = True
End Sub

