2014-01-29 51 views
2

是否有人知道我可以如何在一个并排的垂直行GUI中创建一个16按钮。每个按钮都会为第二个ECT的第一个按钮2设置一个名为menuoutput的变量,其值为1。我一直在测试这个代码,但是我不知道是否有一种方法来为它添加16个按钮。多按钮GUI VBSscript

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

无法在'MsgBox'中一次显示所有按钮。您可以使用自定义的用户窗体来尝试。 –

+0

我该怎么做 – 09stephenb

+0

您使用的是VBA还是纯VBScript? –

回答

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

让我知道这对你的作品。

+0

我无法得到它的工作我得到了黑色的电源外壳窗口,然后只有一个小空白框,并确定按钮 – 09stephenb

+0

嗯...虽然我的作品...我刚刚添加的截图。你修改了代码吗?你可以发布修改后的代码吗? –

+0

我还没有修改它,但我使用的是原始码 – 09stephenb

2

“自然”的方式来添加一个GUI到VBScript是写一个。 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

+2

Microsoft在HTA上提供了一个相当广泛的[教程](http://technet.microsoft.com/en-us/library/ee692768.aspx)。 –