122925
Goto Top

Sapien Powershell - Checkboxen

Hey,
wie kann ich eine Checkbox aus einer anderen Windows Form überprüfen.
Wenn ich auf den Button drücke soll er die Checkbox aus der anderen Form checken.

Es handelt sich hierbei um Sapien Powershell 2012

Content-Key: 276639

Url: https://administrator.de/contentid/276639

Printed on: April 26, 2024 at 08:04 o'clock

Mitglied: 114757
114757 Jul 07, 2015 updated at 13:54:19 (UTC)
Goto Top
Moin,
ist die andere Form ebenfalls eine welche du mit Powershell erstellt hast, oder gehört die Form zu irgend einer anderen Anwendung ?

Gruß jodel32
Mitglied: 122925
122925 Jul 07, 2015 at 14:53:21 (UTC)
Goto Top
Die Beiden Formen wurden in einem Sapien Powershell Project erstellt, dachte deswegen auch, dass beide aufeinander zugreifen können.
Mitglied: 114757
114757 Jul 07, 2015 updated at 16:28:57 (UTC)
Goto Top
Wenn die eine die andere Form aufruft, also die Parent eine Child-Form aufruft geht das selbstverständlich ! Sie muss eben ein Child-Prozess sein damit du auf die Steuerelemente der zweiten Form zugreifen kannst.
Dazu gibt es ja die Überladung der Show() Methode, der du den Owner der Form mitgeben kannst:
https://msdn.microsoft.com/de-de/library/system.windows.forms.form.show( ...

Und die Form-Variable sollte für die Parent-Form natürlich sichtbar sein.
Mitglied: 122925
122925 Jul 08, 2015 at 18:07:25 (UTC)
Goto Top
Kannst du bitte vielleicht mal ein Projekt zum Beispiel machen?
Mitglied: 114757
114757 Jul 08, 2015 updated at 18:39:00 (UTC)
Goto Top
Na gut... weil du hier neu bist ...
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null  
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null  
#endregion

# Variablen der Forms öffentlich deklarieren
$script:form1 = $null
$script:form2 = $null

function GenerateParentForm {

#region Generated Form Objects
$script:form1 = New-Object System.Windows.Forms.Form
$btnStatusCheckbox = New-Object System.Windows.Forms.Button
$btnOpenSecondForm = New-Object System.Windows.Forms.Button
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

$handler_btnStatusCheckbox_Click= 
{
    if ($script:form2 -ne $null){
        # Status der Checkbox in der Child-Form ausgeben
        [System.Windows.Forms.MessageBox]::Show($script:form2.Controls.Item('cb1').Checked)  
    }else{
        [System.Windows.Forms.MessageBox]::Show("Bitte zuerst die Child-Form öffnen")  
    }
}

$handler_btnOpenSecondForm_Click= 
{
    # Child-Form aufrufen
    GenerateChildForm
}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
	$script:form1.WindowState = $InitialFormWindowState
}

#----------------------------------------------
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 104
$System_Drawing_Size.Width = 212
$script:form1.ClientSize = $System_Drawing_Size
$script:form1.DataBindings.DefaultDataSourceUpdateMode = 0
$script:form1.FormBorderStyle = 3
$script:form1.MaximizeBox = $False
$script:form1.MinimizeBox = $False
$script:form1.Name = "form1"  
$script:form1.Text = "Parent Form"  


$btnStatusCheckbox.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 21
$System_Drawing_Point.Y = 56
$btnStatusCheckbox.Location = $System_Drawing_Point
$btnStatusCheckbox.Name = "btnStatusCheckbox"  
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 179
$btnStatusCheckbox.Size = $System_Drawing_Size
$btnStatusCheckbox.TabIndex = 1
$btnStatusCheckbox.Text = "Status of Checkbox in Childform"  
$btnStatusCheckbox.UseVisualStyleBackColor = $True
$btnStatusCheckbox.add_Click($handler_btnStatusCheckbox_Click)

$script:form1.Controls.Add($btnStatusCheckbox)


$btnOpenSecondForm.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 48
$System_Drawing_Point.Y = 12
$btnOpenSecondForm.Location = $System_Drawing_Point
$btnOpenSecondForm.Name = "btnOpenSecondForm"  
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 121
$btnOpenSecondForm.Size = $System_Drawing_Size
$btnOpenSecondForm.TabIndex = 0
$btnOpenSecondForm.Text = "Open Child Form"  
$btnOpenSecondForm.UseVisualStyleBackColor = $True
$btnOpenSecondForm.add_Click($handler_btnOpenSecondForm_Click)

$script:form1.Controls.Add($btnOpenSecondForm)

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $script:form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$script:form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$script:form1.ShowDialog()| Out-Null

} #End Function



function GenerateChildForm {

#region Generated Form Objects
$script:form2 = New-Object System.Windows.Forms.Form
$cb1 = New-Object System.Windows.Forms.CheckBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 97
$System_Drawing_Size.Width = 256
$script:form2.ClientSize = $System_Drawing_Size
$script:form2.DataBindings.DefaultDataSourceUpdateMode = 0
$script:form2.FormBorderStyle = 3
$script:form2.MaximizeBox = $False
$script:form2.MinimizeBox = $False
$script:form2.Name = "form2"  
$script:form2.Text = "Child Form"  


$cb1.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 51
$System_Drawing_Point.Y = 33
$cb1.Location = $System_Drawing_Point
$cb1.Name = "cb1"  
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 200
$cb1.Size = $System_Drawing_Size
$cb1.TabIndex = 0
$cb1.Text = "Change this checkbox, and klick button in parent form"  
$cb1.UseVisualStyleBackColor = $True

$script:form2.Controls.Add($cb1)

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $script:form2.WindowState
#Init the OnLoad event to correct the initial state of the form
$script:form2.add_Load($OnLoadForm_StateCorrection)

#Form als Child von Form1 aufrufen
$script:form2.Show($script:form1) | Out-Null
}

GenerateParentForm
Mitglied: 122925
122925 Jul 08, 2015 at 19:19:50 (UTC)
Goto Top
dankeschön hat mir weitergeholfen face-smile
Mitglied: 114757
114757 Jul 08, 2015 updated at 22:56:24 (UTC)
Goto Top
Zitat von @122925:
dankeschön hat mir weitergeholfen face-smile
Wenns das dann war, den Beitrag dann bitte noch auf gelöst setzen.

-edit- und wech face-sad ... mal wieder eine Eintagsfliege ... sowas nenn ich Dumpfbacke ...
Member: SaschaRD
SaschaRD Jul 10, 2015 updated at 13:58:49 (UTC)
Goto Top
Hallo jodel32,

danke für das Beispiel. Das kann ich gut gebrauchen.

Gruß, Sascha

Edit:
Wie kann ich die Kind-Form schließen (ohne über X)?

Hatte mir dazu einen Button erstellt der dies durchführen soll; leider führt es zu einer Exception face-sad
$SaveButton.Add_Click({$ChildForm.Close()})	

Edit (2):
Habe es gelöst, der Knackpunkt war der Aufruf der Form.
return $ChildForm.Show($MainForm) | Out-Null
in einen ShowDialog geändert.
return $ChildForm.ShowDialog() | Out-Null
Dann lässt sich die Kind-Form auch problemlos schließen =)
Member: colinardo
colinardo Jul 10, 2015 updated at 17:10:17 (UTC)
Goto Top
Zitat von @SaschaRD:
Edit:
Wie kann ich die Kind-Form schließen (ohne über X)?
Hatte mir dazu einen Button erstellt der dies durchführen soll; leider führt es zu einer Exception face-sad
Hallo SaschaRD,
du musst in dem Beispiel von @114757 die Script-Variable der Form benutzen:
$script:form2.Close()
Dann klappt's auch mit dem Nachbarn face-wink

Wenn du die Form mit ShowDialog() öffnest ist die Form keine Childform der Parentform mehr sondern eine vollkommen separate Form, mit diversen Folgen die daraus resultieren.

Grüße Uwe
Member: nico-3012
nico-3012 Jul 15, 2015 updated at 14:26:52 (UTC)
Goto Top
Guten Tag jodel32,
hast du vielleicht bei dem Skript eine Idee wie ich die Checkbox von form2 überprüfen kann, wenn ich ich auf Form1 den button betätige?

#----------------------------------------------
#region Import Assemblies
#----------------------------------------------
[void][Reflection.Assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
[void][Reflection.Assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
[void][Reflection.Assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")  
[void][Reflection.Assembly]::Load("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
[void][Reflection.Assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
[void][Reflection.Assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
[void][Reflection.Assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")  
#endregion Import Assemblies

#Define a Param block to use custom parameters in the project
#Param ($CustomParameter)

function Main {
	Param ([String]$Commandline)
	#Note: This function starts the application
	#Note: $Commandline contains the complete argument string passed to the packager 
	#Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path
	#Note: To get the console output in the Packager (Forms Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList)
	#TODO: Initialize and add Function calls to forms
	
	if((Call-form1_pff) -eq "OK")  
	{
		
	}
	
	$global:ExitCode = 0 #Set the exit code for the Packager
}







#endregion Source: Startup.pfs

#region Source: form1.pff
function Call-form1_pff
{
#region File Recovery Data (DO NOT MODIFY)
<#RecoveryData:
xA4AAB+LCAAAAAAABADNV21v2jAQ/j5p/yHKZ0YIIUClEKlN16nauqKGdfs2mXBpvTo2cpyW7NfP
eSUhoaSvmpAAn+/Nd8+dfdYVeOweeHyKBLI/flAU65LjG0wROcMEvqMAbJ/xQO+vfd/SGnupRLK6
Bh5iRm29P7S0KiHTufwDnlBEvIaZ6sahgKD/E9MVewj7Z1J99t1T2rZ6Sq5qNuoPkk9PcSIiIg4z
CpHgiPSUebQk2PsK8YLdAZ0tJxNkeuZYPzJGMJgeqQqVzs7U9CSq4t1isuKST3UYFZyRUE3dlI7O
OVsDF3Eu4BAMVLj4L6j2eDjpKSNdt7SCaY9QEhg1i9pBXlcgLuYsxEIeULUdaQ2463EAelB2ARux
187ne6kqZ/zG0Eq1L2nym4Q03bO09KfgP5yhxNwJ27x5koS0s2SbR/PUDMY35qEshvpE5mk4HTdi
0hS6kC5igqlM14JH0EEiy23hYgeBDDtD05Q+DTvwL9DynK5gI2WaSdWyLHXP2UkkBKNvnrJlauaF
GRtMO8c/t/e08JtHTwp/F+1ZBXb35kcI1ziMEHFFTOAEeXcOI4zvR1+1imUv8u5Ka7/T5U4R/9/4
uFwDTTQPX4STSZc0VmFSmn0aXCadAFDCZdAZLok/SleHXg8xZRgOIqe+OA5DCGSWISx4c0ps56i5
QBTdQCC19Y8jwYI0W1v0GF3RY+hL35iaY7QyxiMwTEsrLbVbfgWEHrTx6jVx2OIpRw+Y3jzH1sDw
TX/i6/rKHCADPWIrCD3GCV6+z4nk4/JdDP0KyPscCHNZIIzHLvB77MGzgPF4ssplUXnWXFa/LDRe
OPUFKEjFld6RMZQP86yyW6k58dzLX+g11jpVljf2IRQOh7Syk5uxQSu5nSiULaDYr+jetzEnSCRv
WPtT0nCLRbl9FVF3cZy01/zfVpA9yKfyLRBSjBpJQ20QiwZXj5blghdxLPusVlDqAjtjzfYcrVTZ
h1eRJ5rc+zZy+m6q2qinEHocr+th1lqpDgvWiMbVqO9SHLaO5RB3W0tNk3aezCFy0NtxsJ3cOhXm
18reLelZsL2Acl+D6pVUmyC1CvolFqpT6z8/3lrwxA4AAA==#>
#endregion
	#----------------------------------------------
	#region Import the Assemblies
	#----------------------------------------------
	[void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
	[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
	[void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")  
	[void][reflection.assembly]::Load("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
	[void][reflection.assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
	[void][reflection.assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
	[void][reflection.assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")  
	#endregion Import Assemblies

	#----------------------------------------------
	#region Generated Form Objects
	#----------------------------------------------
	[System.Windows.Forms.Application]::EnableVisualStyles()
	$form1 = New-Object 'System.Windows.Forms.Form'  
	$textbox1 = New-Object 'System.Windows.Forms.TextBox'  
	$button1 = New-Object 'System.Windows.Forms.Button'  
	$buttonOpenForm2 = New-Object 'System.Windows.Forms.Button'  
	$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'  
	#endregion Generated Form Objects

	#----------------------------------------------
	# User Generated Script
	#----------------------------------------------
	
	$OnLoadFormEvent={
	#TODO: Initialize Form Controls here
	
	}
	
	
	
	
	
	$buttonOpenForm2_Click={
		#TODO: Place custom script here
		Call-form2_pff
	}
	
	$button1_Click={
		#TODO: Place custom script here
		if ($form1.checkbox.checked = $true) #???????? I would like check, the checkbox from form2.
		{$textbox1.Text = "Checkbox is Checked"}  
	}
		# --End User Generated Script--
	#----------------------------------------------
	#region Generated Events
	#----------------------------------------------
	
	$Form_StateCorrection_Load=
	{
		#Correct the initial state of the form to prevent the .Net maximized form issue
		$form1.WindowState = $InitialFormWindowState
	}
	
	$Form_StoreValues_Closing=
	{
		#Store the control values
		$script:form1_textbox1 = $textbox1.Text
	}

	
	$Form_Cleanup_FormClosed=
	{
		#Remove all event handlers from the controls
		try
		{
			$button1.remove_Click($button1_Click)
			$buttonOpenForm2.remove_Click($buttonOpenForm2_Click)
			$form1.remove_Load($OnLoadFormEvent)
			$form1.remove_Load($Form_StateCorrection_Load)
			$form1.remove_Closing($Form_StoreValues_Closing)
			$form1.remove_FormClosed($Form_Cleanup_FormClosed)
		}
		catch [Exception]
		{ }
	}
	#endregion Generated Events

	#----------------------------------------------
	#region Generated Form Code
	#----------------------------------------------
	#
	# form1
	#
	$form1.Controls.Add($textbox1)
	$form1.Controls.Add($button1)
	$form1.Controls.Add($buttonOpenForm2)
	$form1.ClientSize = '627, 411'  
	$form1.Name = "form1"  
	$form1.StartPosition = 'CenterScreen'  
	$form1.Text = "form1"  
	$form1.add_Load($OnLoadFormEvent)
	#
	# textbox1
	#
	$textbox1.Location = '177, 286'  
	$textbox1.Multiline = $True
	$textbox1.Name = "textbox1"  
	$textbox1.Size = '255, 22'  
	$textbox1.TabIndex = 2
	#
	# button1
	#
	$button1.Location = '177, 208'  
	$button1.Name = "button1"  
	$button1.Size = '255, 59'  
	$button1.TabIndex = 1
	$button1.Text = "button1"  
	$button1.UseVisualStyleBackColor = $True
	$button1.add_Click($button1_Click)
	#
	# buttonOpenForm2
	#
	$buttonOpenForm2.Location = '177, 79'  
	$buttonOpenForm2.Name = "buttonOpenForm2"  
	$buttonOpenForm2.Size = '255, 71'  
	$buttonOpenForm2.TabIndex = 0
	$buttonOpenForm2.Text = "Open Form2"  
	$buttonOpenForm2.UseVisualStyleBackColor = $True
	$buttonOpenForm2.add_Click($buttonOpenForm2_Click)
	#endregion Generated Form Code

	#----------------------------------------------

	#Save the initial state of the form
	$InitialFormWindowState = $form1.WindowState
	#Init the OnLoad event to correct the initial state of the form
	$form1.add_Load($Form_StateCorrection_Load)
	#Clean up the control events
	$form1.add_FormClosed($Form_Cleanup_FormClosed)
	#Store the control values when form is closing
	$form1.add_Closing($Form_StoreValues_Closing)
	#Show the Form
	return $form1.ShowDialog()

}
#endregion Source: form1.pff

#region Source: Globals.ps1
	#--------------------------------------------
	# Declare Global Variables and Functions here
	#--------------------------------------------
	
	
	#Sample function that provides the location of the script
	function Get-ScriptDirectory
	{ 
		if($hostinvocation -ne $null)
		{
			Split-Path $hostinvocation.MyCommand.path
		}
		else
		{
			Split-Path $script:MyInvocation.MyCommand.Path
		}
	}
	
	#Sample variable that provides the location of the script
	[string]$ScriptDirectory = Get-ScriptDirectory
	
	
	
#endregion Source: Globals.ps1

#region Source: form2.pff
function Call-form2_pff
{
#region File Recovery Data (DO NOT MODIFY)
<#RecoveryData:
hQ0AAB+LCAAAAAAABAC9V1tvmzAUfp+0/4B4zkIoIWkkgtTSdarWbVHJur1VhhwaL8aOjGnDfv3M
LYVAGtq1UaQIn4vP7fPxsXUDPnsAnlwggeyPHxTF+sHxPaaIXGIC31EIdsB4eNJfB4GlNXiZRrq6
BR5hRm29f2JpVUK+p/cHfKGIZA1T1U0iAWH/F6YL9hj1L+X2+X9PaWP1lGKr6bA/SH89xYmJiDlM
KcSCI9JTZrFHsP8VkjlbAZ164zEyfXOkT4whDE4nqkKls1M1i0RV/CUmCy7lVIdRwRmJ1MxN6eiM
szVwkRQKDsFAhYv/gmqbY7OnGMbI0kqhPUppYtQ8awdl57ARqp3G2RT9/CBtF3LXDC2KPe/Sb0vL
uKXo4fyex0Iw+u4Z9jIz58hfzVm6t/5ctpvpuGY+EtIR1dYn0gu9Jdv78t2w3EEzL6w+lqYmXeTn
yLuiC9hInS7SWW1TjxTBlK4+/YzgFkcxIq5ICKTaDiOMq/acx9CmX4WJxKu/asnFXcbYAY2Wo6Y7
hpwl+Ktztnl3FGWGPLb5L/CYZmfslPa6Q2Zo9JRR83g/B5lBZ8i8wJ2XoaVW8vriLIoglMWBqJQt
KIldFPsbougeQgmg/lksWJjl+qnoRteiG7oXGKfmCC2M0RAMWaWtpV3LYeQzTrD3BtB6xkoe3zFs
vPmBOWwxvdePY4ijR0zvX2NrYARmMA50fWEOkIEO2/odkuPEhLk8IIwnLvAH7MOrSvbi6BzG4Sjh
FVHJJiFDe4fYtsuyq1gz2aBkE+GlR1+Agty40t5yge1smXetVmpBvPKLIbMmWqfK1oUDiITDIeta
6fXdoG2lnTiS7a3kV/bex5gRJNLRzP6UXvDlYsu+iak7P0v7f/H1pMgegbtLIKScltMrpUEsm3c9
W5YLfsyxvAq0klJXaEzmWVWb03l5ryxiXzSEd+i78ruFaqNeQORzvK4nWWulOixcI5pUc75Lcdg6
ka+QZa0wTdoVFcDlS2XHwXZy67OmuDD3sqRn4dM0VfgaVuer2hNIq2BfIqH67PoHmCgUzoUNAAA=#>
#endregion
	#----------------------------------------------
	#region Import the Assemblies
	#----------------------------------------------
	[void][reflection.assembly]::Load("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
	[void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
	[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
	[void][reflection.assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
	[void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")  
	[void][reflection.assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
	[void][reflection.assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")  
	[void][reflection.assembly]::Load("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
	[void][reflection.assembly]::Load("System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")  
	#endregion Import Assemblies

	#----------------------------------------------
	#region Generated Form Objects
	#----------------------------------------------
	[System.Windows.Forms.Application]::EnableVisualStyles()
	$form2 = New-Object 'System.Windows.Forms.Form'  
	$buttonBackToForm1 = New-Object 'System.Windows.Forms.Button'  
	$Checkbox = New-Object 'System.Windows.Forms.CheckBox'  
	$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'  
	#endregion Generated Form Objects

	#----------------------------------------------
	# User Generated Script
	#----------------------------------------------
	
	$form2_Load={
		#TODO: Initialize Form Controls here
		
	}
	
	$buttonBackToForm1_Click={
		#TODO: Place custom script here
		$form2.Close()
	}
		# --End User Generated Script--
	#----------------------------------------------
	#region Generated Events
	#----------------------------------------------
	
	$Form_StateCorrection_Load=
	{
		#Correct the initial state of the form to prevent the .Net maximized form issue
		$form2.WindowState = $InitialFormWindowState
	}
	
	$Form_StoreValues_Closing=
	{
		#Store the control values
		$script:form2_Checkbox = $Checkbox.Checked
	}

	
	$Form_Cleanup_FormClosed=
	{
		#Remove all event handlers from the controls
		try
		{
			$buttonBackToForm1.remove_Click($buttonBackToForm1_Click)
			$form2.remove_Load($form2_Load)
			$form2.remove_Load($Form_StateCorrection_Load)
			$form2.remove_Closing($Form_StoreValues_Closing)
			$form2.remove_FormClosed($Form_Cleanup_FormClosed)
		}
		catch [Exception]
		{ }
	}
	#endregion Generated Events

	#----------------------------------------------
	#region Generated Form Code
	#----------------------------------------------
	#
	# form2
	#
	$form2.Controls.Add($buttonBackToForm1)
	$form2.Controls.Add($Checkbox)
	$form2.ClientSize = '575, 336'  
	$form2.Name = "form2"  
	$form2.Text = "Form"  
	$form2.add_Load($form2_Load)
	#
	# buttonBackToForm1
	#
	$buttonBackToForm1.Location = '190, 136'  
	$buttonBackToForm1.Name = "buttonBackToForm1"  
	$buttonBackToForm1.Size = '170, 91'  
	$buttonBackToForm1.TabIndex = 1
	$buttonBackToForm1.Text = "Back to Form1"  
	$buttonBackToForm1.UseVisualStyleBackColor = $True
	$buttonBackToForm1.add_Click($buttonBackToForm1_Click)
	#
	# Checkbox
	#
	$Checkbox.Location = '190, 55'  
	$Checkbox.Name = "Checkbox"  
	$Checkbox.Size = '143, 62'  
	$Checkbox.TabIndex = 0
	$Checkbox.Text = "Checkbox"  
	$Checkbox.UseVisualStyleBackColor = $True
	#endregion Generated Form Code

	#----------------------------------------------

	#Save the initial state of the form
	$InitialFormWindowState = $form2.WindowState
	#Init the OnLoad event to correct the initial state of the form
	$form2.add_Load($Form_StateCorrection_Load)
	#Clean up the control events
	$form2.add_FormClosed($Form_Cleanup_FormClosed)
	#Store the control values when form is closing
	$form2.add_Closing($Form_StoreValues_Closing)
	#Show the Form
	return $form2.ShowDialog()

}
#endregion Source: form2.pff

#Start the application
Main ($CommandLine)
Mitglied: 114757
114757 Jul 15, 2015 at 13:45:26 (UTC)
Goto Top
Siehe mein Skript oben das macht das ja ...
Member: nico-3012
nico-3012 Jul 15, 2015 at 14:32:09 (UTC)
Goto Top
ich checks irgendwie nicht, ich stehe auf dem schlauch...
Mitglied: 114757
114757 Jul 15, 2015 updated at 14:38:06 (UTC)
Goto Top
ich checks irgendwie nicht, ich stehe auf dem schlauch...
Schau dir mal Zeile 150 meines Scripts genau an (Parent/Child) und die Position der Form-Variablen (Stichwort: Variable-Scope), dann sollte jedem normalerweise ein Licht aufgehen. Deinen 30 Zeilen langen Code jetzt durchzusehen hab ich keine Zeit, sorry. Für Auftragsarbeiten kannst du mich aber gerne via PM kontaktieren.