Need Help with ContextMenu for RichTextBox

Hi all,
I’m using PSScriptPad to create a windows form and I want to have a contextmenu for a RichTextBox.

I have added ContextStripMenu1 to the project and I have set it as the ContextMenuStrip in the Behavior section of the RTB. The below code was added to my Form.ps1 but I’m totally lost on what to do next to configure the ContextMenuStrip with Cut/Copy/Paste.

My project is a windows form over a powershell script where a long string of comma separated values are pasted into the RichTextBox that will be added to a variable as an array. It seems most of my googling finds very old C# posts or newer C# code which I don’t write or know how to implement.

I appreciate all of the help you all can offer.

$ContextMenuStrip1_Opening = {


This is for anyone else looking for how to implement the ContextMenuStrip in your Powershell Windows Form.

I renamed my CMS to richTxtContextMenuStrip because it will be used exclusively for RichTextBoxes and it has 4 menu items names Cut, Copy, Paste, SelectAll. Here is the code for the click event. Note in PowerShell the Sender Object is $this and Events (e) are $_ .


#---This sets all of the actions for the right-click menu on the RichTextBoxes.

If($_.Button -eq “Left”)
$SourceRichTextBox = $this.SourceControl
$MenuItems = $this.Items

    ForEach($Item in $MenuItems)
        If($Item.Selected -eq "True")
            $MenuAction =  $Item.Name
                "Cut" { $SourceRichTextBox.Cut() }
                "Copy" { $SourceRichTextBox.Copy() }
                "Paste" { $SourceRichTextBox.Paste() }
                "SelectAll" { $SourceRichTextBox.SelectAll() ; $SourceRichTextBox.Focus() }
    #---Do Nothing Right Mouse Button Clicked.


Hope this helps.