多按钮GUI VBScript

时间:2014-01-29 10:42:20

标签: user-interface input menu vbscript messagebox

有没有人知道如何在两个并排的垂直行GUI中制作一个16按钮。对于第二个ECT的第一个按钮2,每个按钮将一个名为menuoutput的变量设置为类似于1的值。我一直在测试这段代码,但我不知道是否有办法添加16个按钮。

x=msgbox("Do you want to start" ,4, "Program")
If x = 6 Then
Wscript.Echo "yes"
Else
Wscript.Echo "no"
End If

2 个答案:

答案 0 :(得分:3)

向VBScript添加GUI的“自然”方式是编写。HTA。为了帮助您入门:

<html>
 <head>
  <Title>menubuttons</Title>
  <hta:application id="menubuttons" scroll = "no">
  <script type="text/vbscript">
   Function window_onload
     Dim spMenu : Set spMenu = document.getElementById("spMenu")
     Dim nB
     For nB = 1 To 5
         Dim oB : Set oB = document.createElement("input")
         oB.setAttribute "type", "button"
         oB.id    = "B" & nB
         oB.value = oB.id
         Set oB.onclick = GetRef("menu")
         spMenu.appendChild oB
     Next
   End Function
   Function menu
     MsgBox Me.id, vbOKOnly, "menu selection"
   End Function
  </script>
 </head>
 <body>
  <span id = "spMenu"></span>
  <hr />
 </body>
</html>

'output'

要了解DOM,请启动here

答案 1 :(得分:2)

VBScript本身不支持GUI创建。你可以采用HTA方式(如上面的Ekkehard.Horner所示,或者你可以采用混合方式来实现这一点。在我的例子中,我使用shell脚本来实现它。

1-使用以下代码

创建Test.ps1脚本
Add-Type -AssemblyName System.Windows.Forms

$Form = New-Object system.Windows.Forms.Form
$Form.Text = "Testing Custom MessageBox"
$Form.Width = 350
$Form.Height = 100
$Form.ControlBox = $False
$Form.StartPosition = "CenterScreen"

$Font = New-Object System.Drawing.Font("Tahoma",10,[System.Drawing.FontStyle]::Bold)
$Form.Font = $Font

$Label = New-Object System.Windows.Forms.Label
$Label.Text = "Custom MsgBox!"
$Label.AutoSize = $True
$Form.Controls.Add($Label)

$Button1 = new-object System.Windows.Forms.Button
$Button1.Location = new-object System.Drawing.Size(5,25)
$Button1.Size = new-object System.Drawing.Size(75,25)
$Button1.Text = "Button1"
$Button1.Add_Click({Write-Host "Button1 was pressed";$Form.Close()})
$Form.Controls.Add($Button1)
$Button2 = new-object System.Windows.Forms.Button
$Button2.Location = new-object System.Drawing.Size(85,25)
$Button2.Size = new-object System.Drawing.Size(75,25)
$Button2.Text = "Button2"
$Button2.Add_Click({Write-Host "Button2 was pressed";$Form.Close()})
$Form.Controls.Add($Button2)
$Button3 = new-object System.Windows.Forms.Button
$Button3.Location = new-object System.Drawing.Size(165,25)
$Button3.Size = new-object System.Drawing.Size(75,25)
$Button3.Text = "Button3"
$Button3.Add_Click({Write-Host "Button3 was pressed";$Form.Close()})
$Form.Controls.Add($Button3)
$Button4 = new-object System.Windows.Forms.Button
$Button4.Location = new-object System.Drawing.Size(245,25)
$Button4.Size = new-object System.Drawing.Size(75,25)
$Button4.Text = "Button4"
$Button4.Add_Click({Write-Host "Button4 was pressed";$Form.Close()})
$Form.Controls.Add($Button4)

$Form.ShowDialog() | Out-Null
Exit 0

2-在你的vbscript文件中调用它 - Test.vbs

Set objShell = CreateObject("WScript.Shell")
Set exec = objShell.Exec("powershell -executionpolicy bypass -noninteractive -file C:\Users\pankaj.jaju\Desktop\Test.ps1")
exec.StdIn.Close()
WScript.Echo exec.StdOut.ReadAll()
Set exec = Nothing
Set objShell = Nothing
WScript.Quit 0

因此,当调用脚本时,您将能够看到消息框 enter image description here

当您按下任何按钮时,您将收到相应的消息 enter image description here

请告诉我这是否适合您。