#Generated Form Function function GenerateForm { ######################################################################## # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0 # Generated By: Alan Kaplan ######################################################################## #region Import the Assemblies [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null #endregion #region Generated Form Objects $form1 = New-Object System.Windows.Forms.Form $DownButton = New-Object System.Windows.Forms.Button $Upbutton = New-Object System.Windows.Forms.Button $listBox1 = New-Object System.Windows.Forms.ListBox $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState #endregion Generated Form Objects #---------------------------------------------- #Generated Event Script Blocks #---------------------------------------------- #Provide Custom Code for events specified in PrimalForms. $handler_DownButton_Click= { #only if the last item isn't the current one if(($ListBox1.SelectedIndex -ne -1) -and ($ListBox1.SelectedIndex -lt $ListBox1.Items.Count - 1) ) { $listbox1.BeginUpdate() #Get starting position $pos = $Listbox1.selectedIndex # add a duplicate of item below in the listbox $ListBox1.items.insert($pos,$listbox1.Items.Item($pos +1)) # delete the old occurrence of this item $ListBox1.Items.RemoveAt($pos +2 ) # move to current item $ListBox1.SelectedIndex = ($pos +1) $ListBox1.EndUpdate() }ELSE{ #Bottom of list, beep [console]::beep(500,100) } } $handler_UpButton_Click= { # only if the first item isn't the current one if($ListBox1.SelectedIndex -gt 0) { $listbox1.BeginUpdate() #Get starting position $pos = $Listbox1.selectedIndex # add a duplicate of original item up in the listbox $ListBox1.items.insert($pos -1,$listbox1.Items.Item($pos)) # make it the current item $ListBox1.SelectedIndex = ($pos -1) # delete the old occurrence of this item $ListBox1.Items.RemoveAt($pos +1) $ListBox1.EndUpdate() }ELSE{ #Top of list, beep [console]::beep(500,100) } } $OnLoadForm_StateCorrection= {#Correct the initial state of the form to prevent the .Net maximized form issue $form1.WindowState = $InitialFormWindowState } #---------------------------------------------- #region Generated Form Code $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 262 $System_Drawing_Size.Width = 284 $form1.ClientSize = $System_Drawing_Size $form1.DataBindings.DefaultDataSourceUpdateMode = 0 $form1.Name = "form1" $form1.Text = "MoveTest" $DownButton.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 224 $System_Drawing_Point.Y = 104 $DownButton.Location = $System_Drawing_Point $DownButton.Name = "DownButton" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 34 $System_Drawing_Size.Width = 48 $DownButton.Size = $System_Drawing_Size $DownButton.TabIndex = 2 $DownButton.Text = "Down" $DownButton.UseVisualStyleBackColor = $True $DownButton.add_Click($handler_DownButton_Click) $form1.Controls.Add($DownButton) $Upbutton.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 224 $System_Drawing_Point.Y = 48 $Upbutton.Location = $System_Drawing_Point $Upbutton.Name = "Upbutton" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 34 $System_Drawing_Size.Width = 48 $Upbutton.Size = $System_Drawing_Size $Upbutton.TabIndex = 1 $Upbutton.Text = "Up" $Upbutton.UseVisualStyleBackColor = $True $Upbutton.add_Click($handler_UpButton_Click) $form1.Controls.Add($Upbutton) $listBox1.DataBindings.DefaultDataSourceUpdateMode = 0 $listBox1.FormattingEnabled = $True $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 27 $System_Drawing_Point.Y = 27 $listBox1.Location = $System_Drawing_Point $listBox1.Name = "listBox1" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 186 $System_Drawing_Size.Width = 182 $listBox1.Size = $System_Drawing_Size $listBox1.TabIndex = 0 # Shutdown the painting of the ListBox as items are added. $listBox1.BeginUpdate() # Loop through and add 10 items to the ListBox. for ($x = 1; $x -le 10; $x++) { $listBox1.Items.Add("Item " + $x.ToString()) | out-null } # Allow the ListBox to repaint and display the new items. $listBox1.EndUpdate(); $form1.Controls.Add($listBox1) #endregion Generated Form Code #Save the initial state of the form $InitialFormWindowState = $form1.WindowState #Init the OnLoad event to correct the initial state of the form $form1.add_Load($OnLoadForm_StateCorrection) #Show the Form $form1.ShowDialog()| Out-Null } #End Function #Call the Function GenerateForm