2015-02-12 122 views
-3

沒有我已經嘗試過,但將工作... 我已經嘗試過的一切,我查看了互聯網,但沒有。 我下載它,然後將其轉換爲.ico,因爲世界上沒有託管服務提供商讓我上傳RAW .ico並從網站獲取它們。 我不想讓圖標可編輯。如何在運行時更改圖標

這是我的代碼

Imports System 
Imports System.IO 
Imports System.Text 

Public Class Form2 
    Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 
     Dim logDirectoryProperties As System.IO.DirectoryInfo 
     If My.Computer.FileSystem.DirectoryExists("C:/fileexplorer") Then 
      Form1.Show() 
     Else 
      logDirectoryProperties = My.Computer.FileSystem.GetDirectoryInfo("C:/fileexplorer") 
      My.Computer.FileSystem.CreateDirectory("C:/fileexplorer") 
      Dim path As String = "C:/fileexplorer/lastactivity.log" 
      Dim fs As FileStream = File.Create(path) 
      Dim info As Byte() = New UTF8Encoding(True).GetBytes("") 
      fs.Write(info, 0, info.Length) 
      fs.Close() 
      My.Computer.Network.DownloadFile("http://icons.iconarchive.com/icons/cornmanthe3rd/plex/512/System-explorer-icon.png", "C:/fileexplorer/logo.png") 
      Dim img As Image = Image.FromFile("C:/fileexplorer/logo.png") 
      img.Save("C:/fileexplorer/logo_dont_edit.ico", System.Drawing.Imaging.ImageFormat.Icon) 
      Form1.Show() 
     End If 
     Me.Icon = New Icon("C:/fileexplorer/logo_dont_edit.ico") 
    End Sub 
End Class 
+0

您是否使用了調試器來執行代碼並*看到*會發生什麼? – Plutonix 2015-02-12 01:37:18

+0

是的,但沒有任何反應。 – 2015-02-12 01:57:15

回答

0

你應該看看WebClient類的DownloadFileAsync方法。

Dim wc As New WebClient 
AddHandler wc.DownloadFileCompleted, AddressOf FileDownloaded 
wc.DownloadFileAsync(Uri, filename) 


Private Sub FileDownloaded(sender As Object, e As System.ComponentModel.AsyncCompletedEventArgs) 
'now assign image here as it has completed it's download 
End Sub