2013-10-19 44 views
0
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
    If ComboBox1.SelectedText = "Anaheim" Then Dim finalpath As String = "C:\hockey055f\data\model\ice0.png" 
    My.Resources.anaice.Save("C:\hockey055f\data\model\ice0.png") 
    MsgBox("Installed!", MsgBoxStyle.Information, "Installed by GoLeafsGo") 

    ElseIf ComboBox1.SelectedText = "Boston" Then If System.IO.File.Exists("c:\hockey055f\data\model\ice0.png") Then 
    System.IO.File.Delete("c:\hockey055f\data\model\ice0.png") 
    My.Resources.bosice.Save("C:\hockey055f\data\model\ice0.png") 
    MsgBox("Installed!", MsgBoxStyle.Information, "Installed by GoLeafsGo") 
End Sub 

這是我的代碼。我試圖做到這樣,當用戶在組合框中選擇一個項目並且用戶按下按鈕時,該文件將從我的資源轉移到上面顯示的目錄。當我點擊第一個值(阿納海姆)時,文件「anaice.png」被傳送,但是(波士頓)值中的「bosice.png」被放入並覆蓋另一個圖像。請幫助!組合框移動資源到磁盤

+0

所以它應該被保存爲...? – Ryan

+0

請縮進並儘量避免在一行上放置。這很難理解。 – Ryan

+0

應該保存爲代表anaice.png的(阿納海姆)值 – user2898546

回答

1

試試這個,但我不知道這是否是你想要什麼:

private finalpath As String = "C:\hockey055f\data\model\ice0.png" 
private res = nothing 

private sub ComboBox_Selectedindexchanged(sender As Object, e As EventArgs) _ 
handles ComboBox1.Selectedindexchanged 

    Select case sender.Selectedindex 

     case is 0:res= My.Resources.anaice 
     case is 1:res= My.Resources.bosice 
     case else 
      msgbox ("select case is out of range") 

    end select 

end sub 

Private Sub Button1_Click(sender As Object, e As EventArgs) _ 
Handles Button1.Click 

    try:io.File.Delete(finalpath):catch:end try 
    res.Save(finalpath) 

    MsgBox("Installed!", MsgBoxStyle.Information, "Installed by GoLeafsGo") 

End Sub 

PS:代碼是動態的書面也許它含有語法錯誤(S)。

+0

非常感謝!在Case開始工作之後,只需添加一個「=」即可。謝謝你的幫助! – user2898546

+0

@ user2898546不客氣我很樂意提供幫助,如果問題得到解決,請將答案標記爲已接受 – ElektroStudios