2016-11-05 51 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 

希望這對你有幫助! :)

相關問題