Vb.net 从桌面用户导入图像到图片框

Vb.net 从桌面用户导入图像到图片框,vb.net,Vb.net,我想从安装在用户桌面上时由project创建的文件夹中导入图片,但每个用户都有不同的用户名,如何从dsektop用户的图片导入 Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) _ Handles Button2.Click PictureBox1.Image = Image.FromFile("(My.Computer.FileSystem.Special

我想从安装在用户桌面上时由project创建的文件夹中导入图片,但每个用户都有不同的用户名,如何从dsektop用户的图片导入

 Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) _
                Handles Button2.Click
      PictureBox1.Image = Image.FromFile("(My.Computer.FileSystem.SpecialDirectories.Desktop, "New folder") \" + ID.Text + ".png")
 end sub 
这是我的密码

 Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) _
                Handles Button2.Click
      PictureBox1.Image = Image.FromFile("(My.Computer.FileSystem.SpecialDirectories.Desktop, "New folder") \" + ID.Text + ".png")
 end sub 
这将解析为当前用户的桌面文件夹。你真的在桌面上创建文件夹吗?通常数据和子文件夹存储在AppData中

 Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) _
                Handles Button2.Click
      PictureBox1.Image = Image.FromFile("(My.Computer.FileSystem.SpecialDirectories.Desktop, "New folder") \" + ID.Text + ".png")
 end sub 
编辑

 Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) _
                Handles Button2.Click
      PictureBox1.Image = Image.FromFile("(My.Computer.FileSystem.SpecialDirectories.Desktop, "New folder") \" + ID.Text + ".png")
 end sub 
我怀疑您可能在其他地方需要此文件夹,即使不需要,也可以保存并“修复”它。其他地方,如应用程序启动时:

 Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) _
                Handles Button2.Click
      PictureBox1.Image = Image.FromFile("(My.Computer.FileSystem.SpecialDirectories.Desktop, "New folder") \" + ID.Text + ".png")
 end sub 
Friend mUserFolder As String
mUserFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
' your code was not adding the required backslash
mUserFolder &= "\Data\"           ' append the sub folder name
现在,要在按钮中加载文件,请单击代码,以便更容易阅读和调试:

 Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) _
                Handles Button2.Click
      PictureBox1.Image = Image.FromFile("(My.Computer.FileSystem.SpecialDirectories.Desktop, "New folder") \" + ID.Text + ".png")
 end sub 
 PictureBox1.Image = Image.FromFile(muserFolder & ID.Text & ".png")

也可以使用
&
连接字符串,而不是
+

是的,我正在桌面上创建文件夹。。。请你能复制我上面的代码并编辑它。。。然后请发布请现在我想检查此文件夹中是否存在文件单击问题旁边的检查以将此问题标记为已修复。然后针对新问题问一个新问题…我不知道你的代码现在是什么样子。请删除双引号。
 Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) _
                Handles Button2.Click
      PictureBox1.Image = Image.FromFile("(My.Computer.FileSystem.SpecialDirectories.Desktop, "New folder") \" + ID.Text + ".png")
 end sub