PrimalForms/PowerShell – Event Behavior: Enter Key and Active Directory Lookup

The next event behavior I wanted to cover was hitting a Enter Key within a textbox control and have it trigger another event.

In this examble I have three basic controls a textbox,a button and a listbox.  I am using the textbox as a Search Textbox, after entering text to search the end user can either press Enter or the ‘find’ button.

First add the Event Handler for the Textbox to response only to the Enterkey.

Next add the Event Handler to search Active Directory using the text from the TextBox($txbFind) after the button($btnFind) is single clicked.

Next the code for handler_button1_Click. First the Event handler clears the listbox ($lstResults) then it searches Active Directory with the text from the Textbox ($txbFind). Then if the results if not null, the handler will list the results in the listbox($lstResults)

$handler_btnFind_Click={
$lstResults.Items.Clear()
$Users = get-qaduser $txbFind.text -service ‘MyDomain.edu’ -sizelimit 0 -includedproperties displayName | Sort displayName | select displayName
 if ($Users -ne $Null) {
  foreach ($User in $Users){
   $lstResults.Items.add($User.displayName)
  }
 }
}

Lastly we add code to the Event handler for the textbox to trigger the button($btnFind) when the Enter Key is pressed and give focus to the listbox($lstResults).

$handler_txbFind_KeyPress=[System.Windows.Forms.KeyPressEventHandler]{
If ($_.KeyChar -eq 13){
 $btnFind.PerformClick()
 $lstResults.Focus()
}
}

The results show the matching users in the listbox

Using this code I created an admin tool that modifys anything from address to exchange administration. Happy Coding!

PrimalForms/PowerShell – Event Behavior: Button Click and Switch Tab

I decided that I would post how to code a few Event Behaviors that could be coded with PowerShell using PrimalForms. You could just use your basic PowerShell Editor but PrimalForms is just my tool of choice.

So I start with a basic form (Two Tabs and a Button)

Then on the Events tab of $button1, double click ‘click’

Add the following code to the Event handler:

 $handler_button1_Click={
#TODO: Place custom script here
     If ($tabpage1.Visible -eq $true) {
          $tabcontrol1.SelectTab(‘tabpage2’)
     }
     ElseIf ($tabpage2.Visible -eq $true) {
           $tabcontrol1.SelectTab(‘tabpage1’)
     }
}

Clicking the button switches from tab to tab. Way cool!

Glimspe of the PrimalForms 2011 and PrimalScript 2011 Release?

I have been waiting impatiently for the release of PrimalForms 2011, my current project requires multi-form support so the sooner I can get my hands on this the better.

Today I found the product pages for PrimalForms 2011 and PrimalScript 2011. Neither product is listed under their current product list.

PrimalForms 2011: http://www.primaltools.com/products/primalforms2011.asp

PrimalScript 2011 http://www.primaltools.com/products/primalscript2011.asp