如何更改MsgBox中的字体

时间:2016-01-05 02:24:37

标签: vbscript

如何更改MsgBox中的字体?

X = MsgBox("I want this to be bold times new roman.")

2 个答案:

答案 0 :(得分:3)

你没有。通过MsgBox显示的对话框使用为系统对话框配置的字体。如果您需要自定义对话框,则需要构建自定义对话框,例如like this

Sub CustomMsgBox(msg)
  Set ie = CreateObject("InternetExplorer.Application")
  ie.Navigate "about:blank"

  While ie.ReadyState <> 4 : WScript.Sleep 100 : Wend

  ie.ToolBar   = False
  ie.StatusBar = False
  ie.Width     = 300
  ie.Height    = 120

  ie.document.body.innerHTML = "<p class='msg'>" & msg & "</p>" & _
    "<p class='ctrl'><input type='hidden' id='OK' name='OK' value='0'>" & _
    "<input type='submit' value='OK' id='OKButton' " &_
    "onclick='document.all.OK.value=1'></p>"

  Set style = ie.document.CreateStyleSheet
  style.AddRule "p.msg", "font-family:times new roman;font-weight:bold;"
  style.AddRule "p.ctrl", "text-align:rightf;"

  ie.Visible = True

  On Error Resume Next
  Do While ie.Document.all.OK.value = 0 
    WScript.Sleep 200
  Loop
  ie.Quit
End Sub

答案 1 :(得分:0)

我会添加pre / pre标签,如下所示,这样格式就不会丢失。然后我会将高度/宽度更改为标准的最小屏幕尺寸,如800x400。然后对于视力障碍者,将StatusBar更改为True,这将启用“更改缩放级别”。

Sub CustomMsgBox(msg)
  Set ie = CreateObject("InternetExplorer.Application")
  ie.Navigate "about:blank"

  While ie.ReadyState <> 4 : WScript.Sleep 100 : Wend

  ie.ToolBar   = False
  ie.StatusBar = True
  ie.Width     = 800
  ie.Height    = 400

  ie.document.body.innerHTML = "<p class='msg'><pre>" & msg & "</pre></p>" & _
    "<p class='ctrl'><input type='hidden' id='OK' name='OK' value='0'>" & _
    "<input type='submit' value='OK' id='OKButton' " &_
    "onclick='document.all.OK.value=1'></p>"

  Set style = ie.document.CreateStyleSheet
  style.AddRule "p.msg", "font-family:times new roman;font-weight:bold;"
  style.AddRule "p.ctrl", "text-align:rightf;"

  ie.Visible = True

  On Error Resume Next
  Do While ie.Document.all.OK.value = 0 
    WScript.Sleep 200
  Loop
  ie.Quit
End Sub