is it possible to have a window to insert data made by powershell?

我的未来我决定 提交于 2019-12-01 08:34:53

TechNet has a useful guide to create a simple input box with powershell using Windows Forms. Essentially you use New-Object to create form objects of the System.Windows.Forms Namespace and set object properties to your liking before you make the form visible. The form object is your "base" object, and from there you can add labels, buttons, listboxes, and other handy form elements like so:

# The Base Form
$myForm = New-Object System.Windows.Forms.Form 
$myForm.Text = "My Form Title"
$myForm.Size = New-Object System.Drawing.Size($width, $height) 
$myForm.StartPosition = "CenterScreen"

# Add a Form Component
$myFormComponent = New-Object System.Windows.Forms.Button
... Set component properties ...
$myForm.Controls.Add($myFormComponent)

.. Add additional components to build a complete form ...

# Show Form
$myForm.Topmost = $True
$myForm.Add_Shown({$myForm.Activate()})
[void] $myForm.ShowDialog()

You'll want to do that once you've finished modifying those components. Following any similar online guide for creating a windows form via powershell should be enough to get you started accepting input.

Once you've accepted input, you can store each type "time, data, server, and name" in different variables and operate on your XML file as needed.


In response to the comment:

Each component you add should be isolated to itself and you can get/set whatever content you want there with variables. Use the text property of the TextBox component. So for example:

$myTextBox = New-Object System.Windows.Forms.TextBox 

// Assign content to a string.
$myTextBox.Text = "Text Goes Here"

// Assign content to an existing variable.
$myTextBox.Text = $myString

// Store content in a variable.
$myString = $myTextBox.Text

For two textfields, you just make another unique textbox as demonstrated above. Remember, your unique components are isolated in scope.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!