Posts Tagged ‘Button’


Why does this button close my form?

Monday, June 29th, 2015 by David Corrales
Have you ever copied a button and found that when a user presses it, the form closes immediately afterwards? We are here to answer: Why does this button close my form? The reason the form closes is that the Button control’s DialogResult property is set to a value other than None. This property tells the form to close after the user has clicked the button without you having to explicitly close the form in the button’s click event script block. So next time you copy an OK or Cancel button, be sure to set the button’s DialogResult to None. For…   More »

PowerShell Studio: Creating Responsive Forms

Wednesday, May 16th, 2012 by David Corrales
When working with GUIs you may have noticed that the Form can freeze when running long scripts. Previously I discussed how to make your loops more responsive in this article, but not every long script comes in the form of a loop. If you truly want to make your forms responsive, you will need to move these slow scripts into another thread and in the PowerShell world this means using jobs. For those of you who aren’t familiar with PowerShell Jobs, they allow you to run scripts while freeing up the console to perform other tasks. In this case it…   More »

PrimalForms 2011: Creating Responsive Loops

Friday, July 15th, 2011 by David Corrales
In the PrimalForms: Preventing Multiple Button Clicks blog article, we introduced the [System.Windows.Forms.Application]::DoEvents method, which allows the application to process form events. This method also becomes very useful when you have a script that runs through a long loop. Here is a sample loop with a progress bar you may encounter in your script:$buttonProcessLoop_Click={ #Reset the Progress Bar $progressbar1.Value = 0 for($i = 0; $i -lt $progressbar1.Maximum; $i++) { #Simulate work sleep -Milliseconds 200 #Step the progress bar $progressbar1.PerformStep() } } When we click the button, the script will go through a loop a number of times and step the…   More »

PrimalForms: Preventing Multiple Button Clicks

Tuesday, July 5th, 2011 by David Corrales
A problem you may face when creating Graphical User Interfaces (GUI) is preventing users from clicking a button multiple times.  It is helpful for our users to learn how to handle this situation. In the following sample, we have a button that is disabled immediately when the button is pressed and then enabled at  the end of click event script. $buttonPress_Click={ $this.Enabled = $False # Output a message on click $textboxOutput.AppendText("Button was clicked`r`n") # Simulate work Start-Sleep -Seconds 2 $this.Enabled = $True } You will find that when you click on the button multiple times while a long event script…   More »

Spotlight on the Button Control

Tuesday, June 7th, 2011 by David Corrales
The Spotlight on Controls series describes the controls, that is, the objects in the System.Windows.Forms namespace, so you can use them effectively when building GUI apps in PowerShell Studio and PrimalScript. Each post focuses on one control and lists its most important properties, methods, and events, including the default event that PowerShell Studio adds to your script when you double-click the control. The posts include many examples written in Windows PowerShell, so you can use them right away. Read more: Shared properties of GUI app controls This post describes the Button control. Button Control [System.Windows.Forms.Button] Creates a clickable button. Used…   More »