2015-02-12 94 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