powershelleventsrichtextboxeventargs

Read EventArgs from Richtextbox-Scroll event via Powershell


$DebugPreference = "Continue"
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$form = New-Object system.Windows.Forms.Form
$form.size  = "400,400"
$rtb = New-Object system.Windows.Forms.RichTextBox
$rtb.size  = "350,350"
$rtb.text = 1..1000
$form.controls.add($rtb)

$rtb.add_VScroll({ 
    param($sender, $eventargs) 
    Write-Debug "Scroll Event $(get-date -format `"mm:ss:ms`")`r`n $($eventargs | out-string) "
})

$form.showdialog()

I am trying to read the eventargs from the VScroll -Event, specifically the ScrollEventArgs.Type-property. I tried it as I usually do (see example code), but for some reason $eventargs just contains a string "system.eventargs". What am I missing/doing wrong?


Solution

  • I have an explanation, but not a solution:

    Type [System.Windows.Forms.ScrollEventArgs] applies to the Scroll event of different controls:

    The Scroll event occurs for the DataGridViewScrollableControlScrollBar, and DataGrid controls.

    By contrast, a rich text-box's VScroll event delegate receives the [System.EventArgs]::Empty singleton, signifying that the event provides no data ([System.EventArgs]::Empty has no properties and therefore stringifies to simply its type name).