2016-11-05 50 views
-3

我是SCCM管理员,所以我打算使用GUI来使用PowerShell进行一些自动化操作,因此我需要从windowsform中输入一些值。谁能帮我从texbox如何从窗体中的文本框中获取字符串

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 
 

 
#Creating Form 
 
$objForm = New-Object System.Windows.Forms.Form 
 
$objForm.Text = "Data Entry Form" 
 
$objForm.Size = New-Object System.Drawing.Size(300,500) 
 
$objForm.StartPosition = "CenterScreen" 
 

 

 

 
#Creating Label 
 
$objLabel = New-Object System.Windows.Forms.Label 
 
$objLabel.Location = New-Object System.Drawing.Size(10,20) 
 
$objLabel.Size = New-Object System.Drawing.Size(280,20) 
 
$objLabel.Text = "Enter collection Name" 
 
$objForm.Controls.Add($objLabel) 
 

 
#Creating Teextbox 
 
$objTextBox = New-Object System.Windows.Forms.TextBox 
 
$objTextBox.Location = New-Object System.Drawing.Size(10,40) 
 
$objTextBox.Size = New-Object System.Drawing.Size(260,20) 
 
$objForm.Controls.Add($objTextBox) 
 
    
 
#How to take input from the Textbox here??? 
 
#so that i can pass the input string to powershell commands

+1

$ objTextBox.Text – LiorA

回答

0

获得价值要设置在C#中的值(例如从文本框中的文本),你这样做你会得到同样的方式! 这里是一个例子:

//To set the text in a textbox 
textBox1.Text = "some text"; 

//To get the text from a textbox 
MessageBox.Show(textBox1.Text); 
//The Messagebox will contain the text from the textbox 

希望这对你有帮助! :)

相关问题