Hi,
I have a GUI that writes all sorts of information to a textbox and i would like to write the contents of the textbox to an event log on form close.
I have an exit button that works fine but when using the red 'X' its a different matter.
Ideally i want to keep the 'contolbox' object.
I have the following that i found on another question which works fine in principal. They both detect the formclosing and i can create a text file etc.
My issue is that its not able to get the textbox text. what am i missing?
1:
$form1_FormClosing=[System.Windows.Forms.FormClosingEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.FormClosingEventArgs]
$logtext = $TextBox1.text
add-content "c:\dump\admingui_closed1.txt" $logtext
}
2:
Register-ObjectEvent -InputObject $form1 -EventName FormClosing -Action {
$logtext = $TextBox1.text
add-content "c:\admingui_closed2.txt" $logtext
#Write-EventLog -LogName "Admin GUI" -Source "Admin GUI" -EventId 666 -Message $logtext
}
Cheers
Geoff
Access textbox contents on formclose
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Access textbox contents on formclose
Register-ObjectEvent does not work with forms. You must add the event to the form.
If you are using PowerShell studio then just use the properties/events panel to add the event.
Code: Select all
$form1_FormClosing = [System.Windows.Forms.FormClosingEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.FormClosingEventArgs]
$logtext = $TextBox1.text
add-content "c:\dump\admingui_closed1.txt" $logtext
}
$form1.add_FormClosing($form1_FormClosing)
Re: Access textbox contents on formclose
Quick and to the point.
I was just missing the last line..
Thank you once again jvierra
I was just missing the last line..
Thank you once again jvierra