【问题标题】:Put the content of a variable in an expression将变量的内容放入表达式中
【发布时间】:2020-03-20 15:57:15
【问题描述】:

我想将变量的内容放在表达式中,现在我解释得更好: 用户选择一个文件,我得到它的扩展名

Dim EXTENSION as String = Path.GetExtension(Path)

很好,我在我的项目中导入了 My.Resources 中的一些 png。 我希望图片框根据文件扩展名显示图像

PicutureBox.Image = My.Resources.EXTENSION

但我不能将 EXTENSION 放在 my.resources 表达式中。 PS:我导入的所有资源都有扩展名


这个文件的资源名称是 My.Resouces.css

我该怎么做? 抱歉我的英语不好,我只是一个 16 岁的意大利人!

【问题讨论】:

    标签: .net vb.net winforms


    【解决方案1】:
    PictureBox.Image = DirectCast(My.Resources.ResourceManager.GetObject(EXTENSION), Image)
    

    【讨论】:

    • 非常感谢!
    【解决方案2】:

    我以你的图片为例,但它对你有用

        Dim ext As String
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            ext = "css" 'here is your extension
            PictureBox1.Image = My.Resources.ResourceManager.GetObject(ext) 'here we load the file
        End Sub
    

    结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-08
      • 1970-01-01
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-08
      • 1970-01-01
      相关资源
      最近更新 更多