如何从Windows窗体中的文本框中获取字符串

时间:2016-11-05 18:50:18

标签: c# winforms powershell-v4.0

我是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 个答案:

答案 0 :(得分: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

希望这对你有所帮助! :)