internet2107
Goto Top

Powershell - 2 x Listbox - synchron scrollen

Hallo,

ist es möglich 2 getrennte Listboxen synchron zu scrollen?
Hat jemand so etwas vielleicht im Einsatz?

Content-Key: 352809

Url: https://administrator.de/contentid/352809

Ausgedruckt am: 19.03.2024 um 03:03 Uhr

Mitglied: H41mSh1C0R
H41mSh1C0R 25.10.2017 um 11:16:45 Uhr
Goto Top
Moin,

sollte schon gehen.

Füge bei dem Event für das Scrollen bei einer Box das Scrollen der 2ten Box ein.

VG
Mitglied: colinardo
Lösung colinardo 25.10.2017 aktualisiert um 18:19:02 Uhr
Goto Top
Servus zusammen.
Zitat von @H41mSh1C0R:
Füge bei dem Event für das Scrollen bei einer Box das Scrollen der 2ten Box ein.
Ja, wenn es solch ein Event "out of the box" für das Listbox-Control (Windows-Forms) gäbe wäre es nicht weiter schlimm face-wink. Aber für sowas gibt es ja das Windows Message API mit dem wir solche Scroll-Events abfangen können.
Schreiben wir und einfach eine abgeleitete Klasse von ListBox welche ein Scroll-Event abfängt und zur Verfügung stellt. Das können wir dann wie gewohnt nutzen und im Event für die eine Listbox die TopIndex Eigenschaft der anderen ListBox festlegen, und umgekehrt.

Bidde:
Add-Type -MemberDefinition @'  
Public Class MyListBox
    Inherits ListBox
    Public Delegate Sub MyListBoxScrollDelegate(Sender As Object, e As MyListBoxScrollArgs)
    Public Event Scroll As MyListBoxScrollDelegate
    ' WM_VSCROLL constants  
    Private Const WM_VSCROLL As Integer = &H115
    Private Const SB_THUMBTRACK As Integer = 5
    Private Const SB_ENDSCROLL As Integer = 8
    Protected Overrides Sub WndProc(ByRef m As Message)
    	' Trap the WM_VSCROLL message to generate the Scroll event  
    	MyBase.WndProc(m)
    	If m.Msg = WM_VSCROLL Then
    		Dim nfy As Integer = m.WParam.ToInt32() And &Hffff
    		If (nfy = SB_THUMBTRACK OrElse nfy = SB_ENDSCROLL) Then
    			RaiseEvent Scroll(Me, New MyListBoxScrollArgs(Me.TopIndex, nfy = SB_THUMBTRACK))
    		End If
    	End If
    End Sub
    Public Class MyListBoxScrollArgs
    	Private mTop As Integer
    	Private mTracking As Boolean
    	Public Sub New(top As Integer, tracking As Boolean)
    		mTop = top
    		mTracking = tracking
    	End Sub
    	Public ReadOnly Property Top() As Integer
    		Get
    			Return mTop
    		End Get
    	End Property
    	Public ReadOnly Property Tracking() As Boolean
    		Get
    			Return mTracking
    		End Get
    	End Property
    End Class
End Class
'@ -name tools -Namespace Win32 -Language VisualBasic -ReferencedAssemblies "System.Windows.Forms" -UsingNamespace "System.Windows.Forms" -EA SilentlyContinue  


function GenerateForm {

#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
$listBox2 = New-Object Win32.tools+MyListBox
$listBox1 = New-Object Win32.tools+MyListBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 196
$System_Drawing_Size.Width = 334
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.FormBorderStyle = 3
$form1.MaximizeBox = $False
$form1.MinimizeBox = $False
$form1.Name = "form1"  
$form1.Text = "Synced Scrolling"  

$listBox2.DataBindings.DefaultDataSourceUpdateMode = 0
$listBox2.FormattingEnabled = $True
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 169
$System_Drawing_Point.Y = 12
$listBox2.Location = $System_Drawing_Point
$listBox2.Name = "listBox2"  
$listBox2.ScrollAlwaysVisible = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 173
$System_Drawing_Size.Width = 153
$listBox2.Size = $System_Drawing_Size
$listBox2.TabIndex = 1
$listBox2.Items.AddRange(1..200)
$listbox2.add_KeyDown({
    $listbox1.TopIndex = $listBox2.TopIndex
})
$listbox2.add_Scroll({
  $listbox1.TopIndex = $_.Top  
})

$form1.Controls.Add($listBox2)

$listBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$listBox1.FormattingEnabled = $True
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 12
$listBox1.Location = $System_Drawing_Point
$listBox1.Name = "listBox1"  
$listBox1.ScrollAlwaysVisible = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 173
$System_Drawing_Size.Width = 151
$listBox1.Size = $System_Drawing_Size
$listBox1.TabIndex = 0
$listBox1.Items.AddRange(1..200)
$listbox1.add_KeyDown({
    $listbox2.TopIndex = $listBox1.TopIndex
})
$listbox1.add_Scroll({
  $listbox2.TopIndex = $_.Top  
})
$form1.Controls.Add($listBox1)


#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
GenerateForm
Grüße Uwe
Mitglied: H41mSh1C0R
H41mSh1C0R 26.10.2017 um 10:04:10 Uhr
Goto Top
Danke Uwe,
schonwieder was was ich mir anschauen werde.
Die Wochenenden werden schonwieder kürzer.
*gg*
Mitglied: internet2107
internet2107 27.10.2017 um 13:01:55 Uhr
Goto Top
Vielen lieben Dank!!!