Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
980 views
in Technique[技术] by (71.8m points)

vbscript - put an image as the background of an input box

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. Putting an image as the background of a input box
  2. Customize the input box like removing the border and change the background color
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:pathoyour.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

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...')

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...