Combobox将资源移动到磁盘

时间:2013-10-19 19:05:45

标签: vb.net

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

这是我的代码。我试图这样做,以便当用户在组合框中选择一个项目并且用户按下按钮时,该文件将从我的资源转移到上面显示的目录。当我点击第一个值(Anaheim)时,传输文件“anaice.png”,然后输入(Boston)值中的“bosice.png”并覆盖另一个图像。求救!

1 个答案:

答案 0 :(得分: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:代码是动态写入的,可能包含语法错误。