VB.Net中路径中的字符非法

时间:2019-06-26 10:10:43

标签: vb.net

我有代码:

If QuestionBox.Text.Contains("#Q1") Then
    QuestionBox.Text = QuestionBox.Text.Replace("Q1", "")
    PictureBox.Image = Image.FromFile(My.Application.Info.DirectoryPath + ("\Gfx\Q1.jpg"))
ElseIf QuestionBox.Text.Contains("Q2") Then
    QuestionBox.Text = QuestionBox.Text.Replace("Q2", "")
    PictureBox.Image = Image.FromFile(My.Application.Info.DirectoryPath + ("\Gfx\Q2.jpg"))
ElseIf QuestionBox.Text.Contains("Q3") Then
    QuestionBox.Text = QuestionBox.Text.Replace("Q3", "")
    PictureBox.Image = Image.FromFile(My.Application.Info.DirectoryPath + ("\Gfx\Q3.jpg"))
ElseIf QuestionBox.Text.Contains("Q4") Then
    QuestionBox.Text = QuestionBox.Text.Replace("Q4", "")
    PictureBox.Image = Image.FromFile(My.Application.Info.DirectoryPath + ("\Gfx\Q4.jpg"))
ElseIf QuestionBox.Text.Contains("Q5") Then
    QuestionBox.Text = QuestionBox.Text.Replace("Q5", "")
    PictureBox.Image = Image.FromFile(My.Application.Info.DirectoryPath + ("\Gfx\Q5.jpg"))
ElseIf QuestionBox.Text.Contains("Q6") Then
    QuestionBox.Text = QuestionBox.Text.Replace("Q6", "")
    PictureBox.Image = Image.FromFile(My.Application.Info.DirectoryPath + ("\Gfx\Q6.jpg"))
ElseIf QuestionBox.Text.Contains("Q7") Then
    QuestionBox.Text = QuestionBox.Text.Replace("Q7", "")
    PictureBox.Image = Image.FromFile(My.Application.Info.DirectoryPath + ("\Gfx\Q7.jpg"))
ElseIf QuestionBox.Text.Contains("Q8") Then
    QuestionBox.Text = QuestionBox.Text.Replace("Q8", "")
    PictureBox.Image = Image.FromFile(My.Application.Info.DirectoryPath + ("\Gfx\Q8.jpg"))
End If

及其缩写版本:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim testString = QuestionBox.Text
    If testString.Contains("Q") Then
        Dim numero As String = Split(testString, "Q")(1)
        QuestionBox.Text = testString.Replace("Q" & numero, "")
        PictureBox.Image = Image.FromFile(My.Application.Info.DirectoryPath + ("\Gfx\Q" & numero & ".jpg"))
    End If

我收到以下错误

  

错误:路径中存在非法字符。

0 个答案:

没有答案