Showing posts with label Powershell and GUI. Show all posts
Showing posts with label Powershell and GUI. Show all posts

Saturday, February 22, 2014

PowerShell and GUI : Checkbox element



Checkbox

clip_image001
Checkbox are very useful element in GUI’s.
When you have to provide options to the user, like, if we want to enable “Active Directory” user account, or disable it, or option of creating email addresses while creating accounts etc.
Checkbox has two major properties, either they can be checked/ticked, or not checked/ticked.
If checkbox is checked / ticked that means it is True ($true).
If checkbox is not checked / ticked that meant it is False ($false).
We can write our logic based on these two properties. We can write that , if checkbox’s checked value is true then do this action and if the checkbox’s checked value is false do this.

Let’s see it in action


Open your favourite PowerShell GUI creator, in my case “PowerShell Studio 2012”.
Create a new form and add these three elements to the form.
1.       Label          clip_image002
2.       Button       clip_image003
3.       Checkbox  clip_image004

You form should be look like this.
clip_image006

Now we are going to implement the following logic.
 If we ticked the checkbox and click on button, our label text will be changed to “Check box is checked.”, and when we un-tick the checkbox and press the button, our text of the label will say “Checkbox is not checked”.
Now double click on our button and it will create a “Mouse Click” event {which we have covered in my past blog post } and add the  below code there.
$checkbox1 is our Checkbox
$button1 is our Button
$label1 is our label

       if ( $checkbox1.Checked -eq $true )
              {
                     $label1.Text = "Checkbox is checked."
                     $label1.ForeColor = 'Green'
             
              }
      
       else
              {
             
                     $label1.Text = "Checkbox is not checked!"
                     $label1.ForeColor = 'Red'
              }
             

clip_image008

Now run the form, in PowerShell studio press Ctrl + 5
You form look like below first.
clip_image009
Now just press on “Button” without ticking on the checkbox. And you will see that our label is changed to the “Checkbox is not checked”.
clip_image010

Now tick on the check and press the button again.
You can see that text of our label is changed to “Checkbox is checked”.
clip_image011

Video
Video on using checkbox

That’s all of now.

See you in my next blog post.

Thanks
Regards
Aman Dhally
clip_image017 clip_image018 clip_image019 clip_image020  clip_image021






Thursday, February 20, 2014

Powershell and GUI : Button element’s Mouse Hover events.

 

Button’s ‘MouseHover’ events.

 

In my previous post, I had shown how to use the “click” event of the Button element.

 Today are going to use the “MouseHover” events of the button.

Mouse Hover

The mouse hover event trigger when we hover the mouse over the button.

To create a “MouseHover” event in the “PowerShell Studio 2012” please do the following.

1.       Open your GUI form.

2.       Open your GUI project file.

3.       Click on “Button” and then go to properties pane of the “button” element.

4.       Click on the “Lightening” ICON and double click on the “MouseHobver”.

5.       clip_image002

6.         You will see that “PowerShell Studio” has created a function code for it.

7.       clip_image003

8.       Now the question is what we want to do when we hover the mouse over the button?

9.       What about changing the colour of the button?

10.   Lets’ change the colour the the button to blue when we move the mouse over it

11.    

12.   $button1.BackColor = 'Blue'

13.    

14.   clip_image004

15.   Press “Ctrl + 5” and try it

16.   clip_image005

17.   Now let’s hove the mouse over it

18.   clip_image006

19.   And here you see J the button is turned in to the Blue.

That’s all for now. See you in my next blog posts.

 

Regards

Aman Dhally

clip_image017 clip_image018 clip_image019 clip_image020  clip_image021

 

 

 

Friday, January 31, 2014

PowerShell and GUI : Working with GUI “Form” properties using PowerShell Studio 2012

 

In my previous post,Powershell Studio 2012 we had created a blank PowerShell GUI form, in this post, I am just sharing about few useful form properties.

Note: We are using Sapien PowerShell Studio 2012

Windows State of the form

If you want to run your GUI to me minimize, or maximize when they run, you are use the “WindowState” field property, to set it as per your needs, either, to stay, it Normal, Minimized or Maximized.

clip_image001[4]

 

Customize Cursor.

Do you want to use a specific cursor for your PowerShell GUI applications, Yes! , you can, using the “Cursor” field property, just click on “Cursor” and choose the cursor which you like to use.

clip_image002[4]

 

Setting Form Border Style

 

You, can also set the style of the form border, using “FormBorderStyle” field property. You can check the below table about the form border style vales and their effects on the form.

 

clip_image003[4]

 

Value

Effect on the form

None

With No Border,

Fixed 3D

You, can’t resize the form, with ICON on the top, with Maximize, Minimize and cancel button  {not able to spot any big difference}

Fixed Single

You, can’t resize the form, with ICON on the top, with Maximize, Minimize and cancel button

Fixed Dialogue

You, can’t resize the form, with NO  ICON, with Maximize, Minimize and cancel button

 

Sizable

You, can resize form, with ICON on the top, with Maximize, Minimize and cancel button

FixedToolWindow

A form with a close button only. You, can’t resize the form.

SizableToolWindow

A form with a close button only. You, can resize the form.

That’s all for today, See you in my next post

 

Thanks

Regards

Aman Dhally

clip_image017 clip_image018 clip_image019 clip_image020  clip_image021