Buttons
One of the main component of any GUI application are buttons. Without Buttons, no GUI applications seems completed.
In my GUI application I use button a lot.
In today’s post we are going to see the basic functionality of the Button element.
Today we are going to cover only the “Click” event of the button. These “Click” event triggers when user press the button.
Let’s get started.
Note: I am using “Sapien PowerShell Studio 2012” for creating GUI’s, you can also download the trial version of it for use and testing. It doesn’t matter which IDE you have used, concept are same everywhere.
1. Open PowerShell studio 2012.
2. Click on “New” and click on “New Form”
4. Choose Empty Form and “Click on Select”.
6. Now from the “Toolbox Panel”, click on “Label” and drop it on the blank form.
8. Click on “Label” properties and change the following.
a. Label’s Text to = “This is a label”
b. Design to = “labelmy”
10. Now drag “Button” from the control pane and drop it on a form.
12. Now double click on “Button” and it will open the script pane,
13. And you can see the Button name and a click method
$button1_Click={ #TODO: Place custom script here
15. } |
16. $button1 is the name of our button and Click is a click method.
17. Now let’s make this button do something.
18. I have added the below line in the button click method
a. $labelmy.Text = 'Oh my God!! Button is pressesd.'
20. So when we press the button, our label text “This is a Label” will be changed to “'Oh my God!! Button is pressesd.'”
21. Let’s see that.
22. Go back to form and click on “Run File” or press “Ctrl + F5”
24. And when the form run, click on the button. And you will see that text of label is changed.
26. Now let’s add some more fun.
27. I have added the one more line of code and change the text for the label.
$button1_Click={ #TODO: Place custom script here
$labelmy.Text = 'Notepad! will be opened.' Start-Process 'notepad.exe'
29. } |
30. Now, when we click on our button, the text of our label will change and it will open a notepad too.
31. Run the form again and click on “button”
32. And you can see that text is changed and a new notepad window is opened.
That’s all for now.
See you in my next blog posts.
Regards
Hi Team Delhi,
ReplyDeleteThis is what I have been after for a week :) I am extremely new at Powershell. This was perfectly explained.
Thank you