2

我想将图像放入msgbox. 搜索后发现不可能,所以我决定把图片放到msgbox. 但我找不到如何做到这一点:

  1. 将图像作为输入框的背景
  2. 自定义输入框,如去除边框和更改背景颜色
4

1 回答 1

4

内置InputBox功能不支持自定义背景。不过,您可以使用Internet Explorer COM 对象构建自定义对话框:

Set ie = CreateObject("InternetExplorer.Application")

ie.Navigate "about:blank"
ie.document.title = "some title"
ie.ToolBar        = False
ie.Resizable      = False
ie.StatusBar      = False
ie.Width          = 300
ie.Height         = 150

Set style = ie.document.CreateStyleSheet()
style.AddRule "body", "background-image: url('C:\path\to\your.jpg')"
Set style = Nothing

Do Until ie.ReadyState = 4 : WScript.Sleep 100 : Loop

ie.document.body.innerHtml = "<p><input type='text' id='userinput'></p>" _
  & "<p><input type='hidden' id='OK' name='OK' value='0'>" _
  & "<input type='submit' value='OK' onClick='VBScript:OK.Value=1'>" _
  & "<input type='submit' value='Cancel' onClick='VBScript:OK.Value=-1'></p>"
ie.Visible = True
ie.document.all.userinput.focus

Do While ie.document.all.OK.value = 0 : WScript.Sleep 100 : Loop

If ie.document.all.OK.value = 1 Then
  'user pressed [OK]
Else
  'user clicked [Cancel]
End If

当然这只是一个非常基本的示例,因此您很可能需要进一步自定义样式以及 HTML 代码。一种可能的改进是以数据 URI的形式包含背景图像:

style.AddRule "body", "background-image: url(data:image/jpeg;base64,/9j/4AA...')

这样您就不必为背景引用外部文件。您可以使用免费的在线编码器将图像文件编码为 base64,例如这个.

于 2013-10-10T10:03:39.893 回答