将图像作为输入框的背景 [英] put an image as the background of an input box

查看:25
本文介绍了将图像作为输入框的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将图像放入 msgbox.在我搜索之后,我发现这是不可能的,所以我决定将图像放在 msgbox 上的输入框的背景中.但我找不到如何做到这一点:

I wanted to put an image in a msgbox. After I searched for it I found it impossible so I decided to put the image into the background of a input box on msgbox. But I can't find how to do that:

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

推荐答案

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

The built-in InputBox function doesn't support custom backgrounds. You can build custom dialogs using the Internet Explorer COM object, though:

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的形式包含背景图像:>

Of course this is just a very basic example, so you most likely need to further customize the styles as well as the HTML code. One possible improvement would be the inclusion of the background image in the form of a data URI:

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

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

That way you won't have to reference an external file for the background. There are free online encoders you could use for encoding image files as base64, for instance this one.

这篇关于将图像作为输入框的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆