Toolbar in PrimalForms

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
HH_Scripting
Posts: 4
Joined: Mon May 02, 2011 11:28 pm

Toolbar in PrimalForms

Post by HH_Scripting » Mon May 02, 2011 11:28 pm

Hello everybody!Can someone please tell me how i can use a click event on a toolbar button?cant add a event for the buttons. only for the toolbar itself.thank you very much!

User avatar
HH_Scripting
Posts: 4
Joined: Mon May 02, 2011 11:28 pm

Toolbar in PrimalForms

Post by HH_Scripting » Tue May 03, 2011 12:41 am

sure this works.but if i add a second button it wont.its like a function for all buttons on the toolbar.but every single button has his own script.

User avatar
jvierra
Posts: 13792
Joined: Tue May 22, 2007 9:57 am
Contact:

Toolbar in PrimalForms

Post by jvierra » Tue May 03, 2011 1:08 am

Here is a complete demo of toolbar and menu use/mplementation.

http://msdn.microsoft.com/en-us/library ... click.aspx

You can copy and paste to a file or directly into PowerShell.

Code: Select all

	
########################################################################
# Code Generated By: SAPIEN Technologies, Inc., PrimalForms 2009 v1.1.11.0
# Generated On: 5/3/2011 9:04 AM
# Generated By: 
# Organization: 
########################################################################
	
#----------------------------------------------
#region Application Functions
#----------------------------------------------
	
function OnApplicationLoad {
 return $true #return true for success or false for failure
}
	
function OnApplicationExit {
 $script:ExitCode = 0 #Set the exit code for the Packager
}
	
#endregion
	
#----------------------------------------------
# Generated Form Function
#----------------------------------------------
function GenerateForm {
	
 #----------------------------------------------
 #region Import Assemblies
 #----------------------------------------------
 [void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
 [void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
 [void][reflection.assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
 [void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
 #endregion
 
 #----------------------------------------------
 #region Generated Form Objects
 #----------------------------------------------
 [System.Windows.Forms.Application]::EnableVisualStyles()
 $form1 = New-Object System.Windows.Forms.Form
 $label1 = New-Object System.Windows.Forms.Label
 $toolbar1 = New-Object System.Windows.Forms.ToolBar
 $listbox1 = New-Object System.Windows.Forms.ListBox
 $toolbarbutton1 = New-Object System.Windows.Forms.ToolBarButton
 $toolbarbutton2 = New-Object System.Windows.Forms.ToolBarButton
 $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
 #endregion Generated Form Objects
	
 #----------------------------------------------
 # User Generated Script
 #----------------------------------------------
	
 
 
 
 
 $FormEvent_Load={
  
  $contextMenuStrip = New-Object System.Windows.Forms.ContextMenuStrip # Create context menu 
  $listbox1.ContextMenuStrip = $contextMenuStrip  
 
  $menuItem1 = New-Object System.Windows.Forms.ToolStripMenuItem -ArgumentList "Hello" 
  $contextMenuStrip.Items.Add($menuItem1) # Add option to context menu 
  $menuItem1.add_Click({ [System.Windows.Forms.MessageBox]::Show("Hello Clicked!") }) 
  
  $menuItem2 = New-Object System.Windows.Forms.ToolStripMenuItem -ArgumentList "Hello Again" 
  $contextMenuStrip.Items.Add($menuItem2) 
  $menuItem2.add_Click({ [System.Windows.Forms.MessageBox]::Show("Hello Again Clicked!") }) 
 }
 
 $handler_toolbar1_ButtonClick=[System.Windows.Forms.ToolBarButtonClickEventHandler]{
     #Event Argument: $_ = [System.Windows.Forms.ToolBarButtonClickEventArgs]
 
  if($_.Button.Name -eq 'toolbarbutton1'){
   [System.Windows.Forms.MessageBox]::Show("You clicked MyButton1")
  }else{
   [System.Windows.Forms.MessageBox]::Show("You clicked the other button")
  }
 
 }
 
 #----------------------------------------------
 # Generated Events
 #----------------------------------------------
 
 $Form_StateCorrection_Load=
 {
  #Correct the initial state of the form to prevent the .Net maximized form issue
  $form1.WindowState = $InitialFormWindowState
 }
 
 #----------------------------------------------
 #region Generated Form Code
 #----------------------------------------------
 #
 # form1
 #
 $form1.Controls.Add($label1)
 $form1.Controls.Add($toolbar1)
 $form1.Controls.Add($listbox1)
 $form1.BackColor = [System.Drawing.Color]::FromArgb(255,61,149,255)
 $form1.ClientSize = New-Object System.Drawing.Size(292,266)
 $form1.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation 
 $form1.Name = "form1"
 $form1.Text = "Primal Form"
 $form1.add_Load($FormEvent_Load)
 #
 # label1
 #
 $label1.BackColor = [System.Drawing.Color]::FromArgb(255,157,185,235)
 $label1.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation 
 $label1.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,1)
 $label1.Location = New-Object System.Drawing.Point(20,61)
 $label1.Name = "label1"
 $label1.Size = New-Object System.Drawing.Size(224,22)
 $label1.TabIndex = 2
 $label1.Text = "Right-Click listbox for context menu."
 #
 # toolbar1
 #
 $toolbar1.AutoSize = $False
 $toolbar1.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle 
 [void]$toolbar1.Buttons.Add($toolbarbutton1)
 [void]$toolbar1.Buttons.Add($toolbarbutton2)
 $toolbar1.ButtonSize = New-Object System.Drawing.Size(28,20)
 $toolbar1.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation 
 $toolbar1.DropDownArrows = $True
 $toolbar1.Location = New-Object System.Drawing.Point(0,0)
 $toolbar1.Name = "toolbar1"
 $toolbar1.ShowToolTips = $True
 $toolbar1.Size = New-Object System.Drawing.Size(292,49)
 $toolbar1.TabIndex = 1
 $toolbar1.add_ButtonClick($handler_toolbar1_ButtonClick)
 #
 # listbox1
 #
 $listbox1.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation 
 $listbox1.FormattingEnabled = $True
 [void]$listbox1.Items.Add("one")
 [void]$listbox1.Items.Add("two")
 [void]$listbox1.Items.Add("three")
 $listbox1.Location = New-Object System.Drawing.Point(31,94)
 $listbox1.Name = "listbox1"
 $listbox1.Size = New-Object System.Drawing.Size(198,160)
 $listbox1.TabIndex = 0
 #
 # toolbarbutton1
 #
 $toolbarbutton1.Name = "toolbarbutton1"
 $toolbarbutton1.Text = "MyButton1"
 #
 # toolbarbutton2
 #
 $toolbarbutton2.Name = "toolbarbutton2"
 $toolbarbutton2.Text = "MyButton2"
 #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($Form_StateCorrection_Load)
 #Show the Form
 return $form1.ShowDialog()
	
} #End Function
	
#Call OnApplicationLoad to initialize
if(OnApplicationLoad -eq $true)
{
 #Create the form
 GenerateForm | Out-Null
 #Perform cleanup
 OnApplicationExit
}
jvierra2011-05-03 08:11:15

Locked