VBA用户窗体中的图像控件不支持jpg文件吗?

huangapple go评论78阅读模式
英文:

Image control in VBA Userform doesn't support jpg file?

问题

在尝试在用户窗体中显示图像时,我收到了以下消息:

'438' 对象不支持此属性或方法图像控件

它的工作方式是,在第一个文本框(img_path)中输入图像目录的路径,在第二个文本框中输入文件的名称(NameImg)。这两个文本框的值被组合成图像控件(ImgControl)的路径。

Private Sub Show_Click()
    Dim show_img As String
    Dim img As String
    
    img = NameImg.Value & ".jpg"
    
    show_img = img_path.Text & img
    ImgControl.Picture = LoadPicture(show_img)
End Sub

Private Sub Select_Click()
    Dim diaFolder As FileDialog
    Dim path As String

    Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
    diaFolder.AllowMultiSelect = False
    diaFolder.Title = "Select a Directory"

    If diaFolder.Show = -1 Then
        path = diaFolder.SelectedItems(1)
        path = path & "\"
        img_path.Text = path
    End If

    Set diaFolder = Nothing
End Sub

jpg文件的路径是正确的,所以我不知道问题出在哪里...

英文:

While trying to display image in UserForm I get this message:

'438' object doesn't support this property or method image control

The way it works is that in 1st textbox(img_path) I input path to img's directory, in 2nd one I input file's name(NameImg). Both textboxes' values are combined into path to the image for image control (ImgControl).

Private Sub Show_Click()
Dim show_img As String
Dim img As String
ing = NameImg.Value + ".jpg"


show_img = img_path.Text + img
ImgControl = LoadPicture(show_img)

End Sub

Private Sub Select_Click()
Dim diaFolder As FileDialog
    Dim path As String
    
    Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
    diaFolder.AllowMultiSelect = False
    diaFolder.Title = "Select a Directory"
    
    If diaFolder.Show = -1 Then
        path = diaFolder.SelectedItems(1)
        path = path + "\"
        img_path.Text = path
    End If
    
    Set diaFolder = Nothing
End Sub

The path to jpg file is correct so I don't know what's the problem...

答案1

得分: 0

ImgControl.Picture = LoadPicture(show_img)

英文:

As @Tim Williams pointed out I forgot about Picture property here:
ImgControl = LoadPicture(show_img)
it should be

ImgControl.Picture = LoadPicture(show_img)

huangapple
  • 本文由 发表于 2023年6月2日 04:01:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76385314.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定