![sapien powershell studio event logs sapien powershell studio event logs](https://www.sapien.com/blog/wp-content/uploads/2019/06/Pkg_ScriptEngine2_2019-06-19_10-46-45.png)
Removing the code doesn’t remove the “ Button1” object from the GUI form: In our example we remove the code block for the “ Button1” control: What will happened if you decide to delete the code block for the control? This is important and it’s done behind the scene. Here’s where it gets interesting! Every time you drag/drop to add a control-the event handler for that control gets registered in the form.
#SAPIEN POWERSHELL STUDIO EVENT LOGS REGISTRATION#
But, what’s really happening when you add any control to the form? Control Event Handler Registration
![sapien powershell studio event logs sapien powershell studio event logs](https://i0.wp.com/www.sapien.com/blog/wp-content/uploads/2012/09/PowerShell-Studio-Manual.png)
The result of adding the code inside the Button control is that when the form is executed, pressing “ Button1” will execute the code behind the control. Simply double-click on the snippet and the code will be automatically added to the control: In the following example I am adding the “ Message Box (Yes / No)” code from the PowerShell Studio snippet collection into the “ Button1” control. The image below shows some other controls added to a form: The Button Control is the one you’ll click that will run your code behind the control and is the most used control in any Windows Forms application. There are many controls we can add to our Windows Form. This is fine until you start trying to copy/paste an actual event code block. You will most likely be using your own code snippets to add behind the form controls, as well as the snippets available in PowerShell Studio, and perhaps snippets from someone else. PowerShell Studio has a selection of Windows Form templates that you can use to speed up your development.