question

NizamuddinShaikh-0886 avatar image
0 Votes"
NizamuddinShaikh-0886 asked NizamuddinShaikh-0886 published

Need help in Windows Forms.

Hi All,

I am seeking help in windows from. I have created following script using PoshGui. There is one more another script (windows.ps1) where i have created All functions in that cover these Check boxes and finally i have serves.txt file.

The intention is, when the user open the GUI and select the multiple check boxes of function names, based on these checks and provided server list (server.txt) in GUI it should run the functions.

can someone help me in logic mapping my windows.pas1(functions file) to my GUI. I am not that much friendly with windows form hence can't bind the logic.








<# This form was created using POSHGUI.com a free online gui designer for PowerShell
.NAME
New

>


Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

$form = New-Object system.Windows.Forms.Form
$form.ClientSize = New-Object System.Drawing.Point(547,400)
$form.text = "TestForm"
$form.TopMost = $false



$GrpBoxRuntimeParameters = New-Object system.Windows.Forms.Groupbox
$GrpBoxRuntimeParameters.height = 80
$GrpBoxRuntimeParameters.width = 250
$GrpBoxRuntimeParameters.text = "Runtime Parameters"
$GrpBoxRuntimeParameters.location = New-Object System.Drawing.Point(20,22)

$CheckBoxPrechecks = New-Object system.Windows.Forms.CheckBox
$CheckBoxPrechecks.text = "Pre Check"
$CheckBoxPrechecks.AutoSize = $true
$CheckBoxPrechecks.width = 95
$CheckBoxPrechecks.height = 20
$CheckBoxPrechecks.location = New-Object System.Drawing.Point(20,20)
$CheckBoxPrechecks.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$BtnExecute = New-Object system.Windows.Forms.Button
$BtnExecute.text = "Execute"
$BtnExecute.width = 70
$BtnExecute.height = 30
$BtnExecute.location = New-Object System.Drawing.Point(437,347)
$BtnExecute.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)


$BtnServerList = New-Object system.Windows.Forms.Button
$BtnServerList.text = "Server List"
$BtnServerList.width = 100
$BtnServerList.height = 24
$BtnServerList.location = New-Object System.Drawing.Point(405,300)
$BtnServerList.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$Txtfilepath = New-Object system.Windows.Forms.TextBox
$Txtfilepath.multiline = $false
$Txtfilepath.text = "`"C:\PS\Document as code\Input\Servers.txt`""
$Txtfilepath.width = 382
$Txtfilepath.height = 20
$Txtfilepath.location = New-Object System.Drawing.Point(20,300)
$Txtfilepath.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$GrpBoxOutPut = New-Object system.Windows.Forms.Groupbox
$GrpBoxOutPut.height = 59
$GrpBoxOutPut.width = 190
$GrpBoxOutPut.text = "Output Format"
$GrpBoxOutPut.location = New-Object System.Drawing.Point(300,19)

$RadioButtonWord = New-Object system.Windows.Forms.RadioButton
$RadioButtonWord.text = "Word"
$RadioButtonWord.AutoSize = $true
$RadioButtonWord.width = 104
$RadioButtonWord.height = 20
$RadioButtonWord.location = New-Object System.Drawing.Point(9,23)
$RadioButtonWord.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$RadioButtonExcel = New-Object system.Windows.Forms.RadioButton
$RadioButtonExcel.text = "Excel"
$RadioButtonExcel.AutoSize = $true
$RadioButtonExcel.width = 104
$RadioButtonExcel.height = 20
$RadioButtonExcel.location = New-Object System.Drawing.Point(65,23)
$RadioButtonExcel.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$RadioButtonBoth = New-Object system.Windows.Forms.RadioButton
$RadioButtonBoth.text = "Both"
$RadioButtonBoth.AutoSize = $true
$RadioButtonBoth.width = 104
$RadioButtonBoth.height = 20
$RadioButtonBoth.location = New-Object System.Drawing.Point(124,23)
$RadioButtonBoth.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$GrpBoxSections = New-Object system.Windows.Forms.Groupbox
$GrpBoxSections.height = 170
$GrpBoxSections.width = 471
$GrpBoxSections.text = "Sections"
$GrpBoxSections.location = New-Object System.Drawing.Point(19,120)
$GrpBoxSections.BackColor = [System.Drawing.ColorTranslator]::FromHtml("#9b9b9b")

$CheckBoxServerConfiguration = New-Object system.Windows.Forms.CheckBox
$CheckBoxServerConfiguration.text = "Server Configuration"
$CheckBoxServerConfiguration.AutoSize = $true
$CheckBoxServerConfiguration.width = 135
$CheckBoxServerConfiguration.height = 20
$CheckBoxServerConfiguration.location = New-Object System.Drawing.Point(20,25)
$CheckBoxServerConfiguration.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$CheckBoxServerNW = New-Object system.Windows.Forms.CheckBox
$CheckBoxServerNW.text = "Network"
$CheckBoxServerNW.AutoSize = $true
$CheckBoxServerNW.width = 95
$CheckBoxServerNW.height = 20
$CheckBoxServerNW.location = New-Object System.Drawing.Point(20,47)
$CheckBoxServerNW.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$RolesandFeatures = New-Object system.Windows.Forms.CheckBox
$RolesandFeatures.text = "Roles and Features"
$RolesandFeatures.AutoSize = $true
$RolesandFeatures.width = 135
$RolesandFeatures.height = 20
$RolesandFeatures.location = New-Object System.Drawing.Point(20,69)
$RolesandFeatures.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$CheckBoxInstalledFeatures = New-Object system.Windows.Forms.CheckBox
$CheckBoxInstalledFeatures.text = "Installed Features"
$CheckBoxInstalledFeatures.AutoSize = $true
$CheckBoxInstalledFeatures.width = 135
$CheckBoxInstalledFeatures.height = 20
$CheckBoxInstalledFeatures.location = New-Object System.Drawing.Point(20,91)
$CheckBoxInstalledFeatures.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$CheckBoxLicensing = New-Object system.Windows.Forms.CheckBox
$CheckBoxLicensing.text = "Licensing"
$CheckBoxLicensing.AutoSize = $true
$CheckBoxLicensing.width = 135
$CheckBoxLicensing.height = 20
$CheckBoxLicensing.location = New-Object System.Drawing.Point(20,111)
$CheckBoxLicensing.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$CheckBoxStorage = New-Object system.Windows.Forms.CheckBox
$CheckBoxStorage.text = "Storage"
$CheckBoxStorage.AutoSize = $true
$CheckBoxStorage.width = 135
$CheckBoxStorage.height = 20
$CheckBoxStorage.location = New-Object System.Drawing.Point(254,27)
$CheckBoxStorage.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$CheckBoxInstalledSoftware = New-Object system.Windows.Forms.CheckBox
$CheckBoxInstalledSoftware.text = "Installed Software"
$CheckBoxInstalledSoftware.AutoSize = $true
$CheckBoxInstalledSoftware.width = 135
$CheckBoxInstalledSoftware.height = 20
$CheckBoxInstalledSoftware.location = New-Object System.Drawing.Point(254,49)
$CheckBoxInstalledSoftware.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$CheckBoxServerHealth = New-Object system.Windows.Forms.CheckBox
$CheckBoxServerHealth.text = "ServerHealth"
$CheckBoxServerHealth.AutoSize = $true
$CheckBoxServerHealth.width = 135
$CheckBoxServerHealth.height = 20
$CheckBoxServerHealth.location = New-Object System.Drawing.Point(254,71)
$CheckBoxServerHealth.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$CheckBoxQA = New-Object system.Windows.Forms.CheckBox
$CheckBoxQA.text = "QA"
$CheckBoxQA.AutoSize = $true
$CheckBoxQA.width = 135
$CheckBoxQA.height = 20
$CheckBoxQA.location = New-Object System.Drawing.Point(254,96)
$CheckBoxQA.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$CheckBoxSMEArea = New-Object system.Windows.Forms.CheckBox
$CheckBoxSMEArea.text = "SME Area(for LLD doc)"
$CheckBoxSMEArea.AutoSize = $true
$CheckBoxSMEArea.width = 135
$CheckBoxSMEArea.height = 20
$CheckBoxSMEArea.location = New-Object System.Drawing.Point(255,118)
$CheckBoxSMEArea.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$form.controls.AddRange(@($GrpBoxRuntimeParameters,$BtnExecute,$BtnServerList,$Txtfilepath,$GrpBoxOutPut,$GrpBoxSections))
$GrpBoxRuntimeParameters.controls.AddRange(@($CheckBoxPrechecks))
$GrpBoxOutPut.controls.AddRange(@($RadioButtonWord,$RadioButtonExcel,$RadioButtonBoth))
$GrpBoxSections.controls.AddRange(@($CheckBoxServerConfiguration,$CheckBoxServerNW,$RolesandFeatures,$CheckBoxInstalledFeatures,$CheckBoxLicensing,$CheckBoxStorage,$CheckBoxInstalledSoftware,$CheckBoxServerHealth,$CheckBoxQA,$CheckBoxSMEArea))




Write your logic code here


[void]$form.ShowDialog()

162665343591-capture.png


windows-server-powershellwindows-forms
capture.png (9.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered IanXue-MSFT edited

Hi,

You need to add functions to the execute button

 $BtnExecute.Add_Click({ YourFunction })


Best Regards,
Ian
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.