Mark,
Maybe you can use this, I got it once from Fergus Cooney and changed it, the
purpose was to do things with images, which was then not yet in standard
programs.
It is used as a class for a form with images, however I think it is better
that you find that for yourself.
\\\
Public Class Enlarger
Private Shared EnlargerRectangle As Rectangle
Private Shared mVertical As Boolean
Private Shared imgHeight As Integer
Private Shared imgWidth As Integer
Private Shared LastMouseX As Integer
Private Shared LastMouseY As Integer
Public Shared ReadOnly Property Vertical() As Boolean
Get
Return mVertical
End Get
End Property
Public Shared ReadOnly Property Rectangle() As Rectangle
Get
Return EnlargerRectangle
End Get
End Property
Public Shared Sub Initialize(ByVal clientRectangle As Rectangle)
EnlargerRectangle = clientRectangle
imgHeight = EnlargerRectangle.Height
imgWidth = EnlargerRectangle.Width
If imgHeight < imgWidth Then
mVertical = True 'reverse because of next action
Else
mVertical = False
End If
End Sub
Public Shared Sub setOrientation()
If mVertical Then
mVertical = False
Dim testhight As Integer
If imgWidth > imgHeight * 2 / 3 Then
testhight = imgWidth * 2 / 3
Else
testhight = imgHeight
End If
Dim NewWidth = testhight * 3 / 2
Enlarger.Reset(NewWidth, testhight)
Else
'It has to be vertical
mVertical = True
Dim testwidth As Integer
If imgWidth > imgHeight * 2 / 3 Then
testwidth = imgHeight * 2 / 3
Else
testwidth = imgWidth
End If
Dim NewHight = testwidth * 3 / 2
Enlarger.Reset(testwidth, NewHight)
End If
End Sub
Private Shared Sub Reset(ByVal width As Integer, ByVal hight As Integer)
EnlargerRectangle.Location = New Point(0, 0)
EnlargerRectangle.Width = width
EnlargerRectangle.Height = hight
End Sub
Public Shared Sub move(ByVal curMouseX As Integer, ByVal curMouseY As
Integer, ByVal imgTopLeft As Point)
Dim newX As Integer = EnlargerRectangle.X
Dim newY As Integer = EnlargerRectangle.Y
Dim newHeight As Integer = EnlargerRectangle.Height
Dim newWidth As Integer = EnlargerRectangle.Width
If (Control.ModifierKeys And Keys.Control) Then
newWidth = EnlargerRectangle.Width + (curMouseX - LastMouseX)
If newWidth < 10 Then
newWidth = 10
End If
If newWidth > imgWidth Then
newWidth = imgWidth
End If
If mVertical Then
newHeight = (newWidth * 3) \ 2
If newHeight > imgHeight Then
newHeight = imgHeight
newWidth = (newHeight * 2) \ 3
End If
Else
newHeight = (newWidth * 2) \ 3
If newHeight > imgHeight Then
newHeight = imgHeight
newWidth = (newHeight * 3) \ 3
End If
End If
Else
newX += (curMouseX - LastMouseX) 'step
newY += (curMouseY - LastMouseY) 'step
If newX < 0 Then
newX = 0
End If
If newY < 0 Then
newY = 0
End If
If newX + EnlargerRectangle.Width > imgWidth Then
newX = imgWidth - EnlargerRectangle.Width
End If
If newY + EnlargerRectangle.Height > imgHeight Then
newY = imgHeight - EnlargerRectangle.Height
End If
End If
EnlargerRectangle = New Rectangle(newX, newY, newWidth, newHeight)
Mousedown(imgTopLeft)
End Sub
Public Shared Sub Mousedown(ByVal imgTopLeft As Point)
LastMouseX = EnlargerRectangle.X + EnlargerRectangle.Width - 30
LastMouseY = EnlargerRectangle.Y + EnlargerRectangle.Height - 30
Cursor.Position = New Point(imgTopLeft.X + LastMouseX, imgTopLeft.Y
+ LastMouseY)
End Sub
End Class
///
Cor