【问题标题】:How to change font in MsgBox如何更改 MsgBox 中的字体
【发布时间】:2016-01-05 02:24:37
【问题描述】:

如何更改MsgBox 中的字体?

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

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    你没有。通过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
    

    【讨论】:

      【解决方案2】:

      我会添加如下所示的 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
      

      【讨论】:

      • 这似乎是附加在另一个答案上的评论,而不是实际答案本身。
      • 同意。这是一个微小的变化。
      猜你喜欢
      • 1970-01-01
      • 2011-06-27
      • 2015-07-03
      • 1970-01-01
      • 1970-01-01
      • 2017-09-02
      • 1970-01-01
      • 2011-07-31
      相关资源
      最近更新 更多