MS SnapPanel ScrollBar

This commit is contained in:
Developer01
2025-04-10 18:01:00 +02:00
parent ef32824a08
commit 0d5bfef93f
6 changed files with 274 additions and 52 deletions

View File

@@ -8,11 +8,11 @@ Imports System.Runtime.InteropServices
' Werte der Assemblyattribute überprüfen
<Assembly: AssemblyTitle("SnapPanel")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("SnapPanel")>
<Assembly: AssemblyCopyright("Copyright © 2021")>
<Assembly: AssemblyTitle("DigitalData.SnapPanel")>
<Assembly: AssemblyDescription("Integriert ein SnapPanel für das Design von Forms")>
<Assembly: AssemblyCompany("Digital Data GmbH, Heuchelheim")>
<Assembly: AssemblyProduct("DigitalData.SnapPanel")>
<Assembly: AssemblyCopyright("")>
<Assembly: AssemblyTrademark("")>
<Assembly: ComVisible(False)>
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' indem Sie "*" wie unten gezeigt eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.0.1.0")>
<Assembly: AssemblyFileVersion("1.0.1.0")>
<Assembly: AssemblyVersion("2.0.1.0")>
<Assembly: AssemblyFileVersion("2.0.1.0")>

View File

@@ -5,7 +5,9 @@ Public Class ClassSnapPanel
Private _ShowGrid As Boolean = True
Private _GridSize As Integer = 16
Public Sub New()
Me.AutoScroll = True ' Scrollbars aktivieren
End Sub
Public Property GridSize As Integer
Get
Return _GridSize
@@ -30,12 +32,14 @@ Public Class ClassSnapPanel
AddHandler e.Control.LocationChanged, AddressOf AlignToGrid
AddHandler e.Control.DragDrop, AddressOf AlignToGrid
MyBase.OnControlAdded(e)
UpdateScrollArea()
End Sub
Protected Overrides Sub OnControlRemoved(e As ControlEventArgs)
RemoveHandler e.Control.LocationChanged, AddressOf AlignToGrid
RemoveHandler e.Control.DragDrop, AddressOf AlignToGrid
MyBase.OnControlRemoved(e)
UpdateScrollArea()
End Sub
Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
@@ -51,6 +55,23 @@ Public Class ClassSnapPanel
Dim x As Integer = Math.Round(item.Left / _GridSize) * _GridSize
Dim y As Integer = Math.Round(item.Top / _GridSize) * _GridSize
item.Location = New Point(x, y)
UpdateScrollArea()
End If
End Sub
Private Sub UpdateScrollArea()
Dim maxWidth As Integer = 0
Dim maxHeight As Integer = 0
' Größte X- und Y-Koordinate der enthaltenen Controls bestimmen
For Each ctrl As Control In Controls
Dim right As Integer = ctrl.Right
Dim bottom As Integer = ctrl.Bottom
If right > maxWidth Then maxWidth = right
If bottom > maxHeight Then maxHeight = bottom
Next
' Scrollbereich setzen
Me.AutoScrollMinSize = New Size(maxWidth, maxHeight)
End Sub
End Class