Hier noch eine erweiterte Version
Imports System.ComponentModel
''' <summary>
''' Das Control stellt ein Image ViewPort zur Verfügung.
''' </summary>
''' <remarks>
''' Mit der Eigenschaft Image wird das darzustellende Bild in die
''' interne Picturebox geladen. Die Eigenschaften StepSizeX und Y
''' bestimmen die Schrittweite für das Scrollen mit den Cursor Tasten.
''' </remarks>
Public Class ViewPort
Inherits ScrollableControl
Private m_ViewBox As PictureBox
Private m_StepSizeX As Integer = 10
Private m_StepSizeY As Integer = 10
Private xPos As Integer = 0
Private yPos As Integer = 0
Public Sub New()
m_ViewBox = New PictureBox
With m_ViewBox
.Location = New Point(0, 0)
.SizeMode = PictureBoxSizeMode.AutoSize
.Visible = True
End With
Me.Controls.Add(m_ViewBox)
Me.AutoScroll = True
AddHandler m_ViewBox.Click, AddressOf ViewBoxClick
End Sub
Protected Overrides Function ProcessDialogKey(ByVal keyData As _
System.Windows.Forms.Keys) As Boolean
Select Case keyData
Case Keys.Up, Keys.Down, Keys.Left, Keys.Right
' Do nothing
Case Else
Return MyBase.ProcessDialogKey(keyData)
End Select
End Function
<DefaultValueAttribute(GetType(Image), "none"), _
Category("Appearance"), _
Description("Das zu scrollende Image")> _
Public Property Image() As Image
Get
Return m_ViewBox.Image
End Get
Set(ByVal value As Image)
m_ViewBox.Image = value
m_ViewBox.Invalidate()
End Set
End Property
<DefaultValueAttribute(GetType(PictureBoxSizeMode), "AutoSize"), _
Category("Behavior"), _
Description("Darstellungsmodus des Images")> _
Public Property SizeMode() As PictureBoxSizeMode
Get
Return m_ViewBox.SizeMode
End Get
Set(ByVal value As PictureBoxSizeMode)
m_ViewBox.SizeMode = value
End Set
End Property
<DefaultValueAttribute(10), _
Category("Behavior"), _
Description("Scroll Schrittweite in X-Richtung")> _
Public Property StepSizeX() As Integer
Get
Return m_StepSizeX
End Get
Set(ByVal value As Integer)
m_StepSizeX = value
End Set
End Property
<DefaultValueAttribute(10), _
Category("Behavior"), _
Description("Scroll Schrittweite in Y-Richtung")> _
Public Property StepSizeY() As Integer
Get
Return m_StepSizeY
End Get
Set(ByVal value As Integer)
m_StepSizeY = value
End Set
End Property
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)
m_ViewBox.Size = New Size(Me.ClientSize.Width, Me.ClientSize.Height)
End Sub
Private Sub ViewPort_KeyDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.Left
If xPos > m_StepSizeX Then
xPos -= m_StepSizeX
Else
xPos = 0
End If
Case Keys.Right
xPos += m_StepSizeX
If xPos + Me.ClientSize.Width > m_ViewBox.ClientSize.Width Then
xPos = m_ViewBox.ClientSize.Width - Me.ClientSize.Width
End If
Case Keys.Up
If yPos > m_StepSizeY Then
yPos -= m_StepSizeY
Else
yPos = 0
End If
Case Keys.Down
yPos += m_StepSizeY
If yPos + Me.ClientSize.Height > m_ViewBox.ClientSize.Height Then
yPos = m_ViewBox.ClientSize.Height - Me.ClientSize.Height
End If
End Select
Me.AutoScrollPosition = New Point(xPos, yPos)
End Sub
Private Sub ViewBoxClick(ByVal sender As Object, ByVal e As System.EventArgs)
Me.Focus()
End Sub
Private Sub ViewPort_MouseWheel(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
yPos = System.Math.Abs(m_ViewBox.Location.Y)
End Sub
Private Sub ViewPort_Scroll(ByVal sender As Object, ByVal e As _
System.Windows.Forms.ScrollEventArgs) Handles Me.Scroll
Select Case e.ScrollOrientation
Case ScrollOrientation.HorizontalScroll : xPos = e.NewValue
Case ScrollOrientation.VerticalScroll : yPos = e.NewValue
End Select
End Sub
End Class Gruß
Gru?
---------------------------------------------------
Snoopy sagt - vb@rchiv find ich gut...
Schon gesehen? OSMMapViewer V2 Control |