Access textbox contents on formclose
Posted: Thu Dec 27, 2018 8:55 am
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
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