Runtime resizeable images with autoscroll problem

MarkD

New member
Joined
May 24, 2005
Messages
2
Programming Experience
5-10
Hi,

I'm trying to create an image editor similar to paint to include in an app. I've got a scrollable panel with a picturebox on it. Around the picturebox are 8 5x5 labels to act as grabpoints for resizing (i'm sure there is a correct technical name for them but I'm sure you know what I mean). So far, so peachy, if you drag a grabpoint it will resize the image but things are going a bit funny when the image is scrolled. I'll try to describe whats happening.

1. Use the Down grabpoint to extend the image off the screen
2. Scroll down to the bottom of the image
3. Grab the Down grabpoint and move it up 1 pixel at a time to reduce the height of the image

At this point after I have moved the mouse up about 10 pixels it starts auto-scrolling up the screen. I haven't set the autoscroll margin, so its set to zero so I wouldn't expect it to autoscroll until the mouse reached the top of the display.

I've included the project although its a dll

Here's the code

Private _mouseDown As Boolean
Private _rs As String

Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles resizeR.MouseDown, resizeD.MouseDown, resizeDR.MouseDown

_mouseDown = True
_rs = CType(sender, Windows.Forms.Label).Name
End Sub

Private Sub Label1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles resizeR.MouseUp, resizeD.MouseUp, resizeDR.MouseUp
_mouseDown = False
_rs = ""
End Sub

Private Sub resizeboxMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles resizeD.MouseMove, resizeR.MouseMove, resizeDR.MouseMove

If _mouseDown Then

Select Case _rs
Case "resizeD"
PictureBox1.Height = Panel1.PointToClient(Panel1.MousePosition).Y - Panel1.AutoScrollPosition.Y
Case "resizeR"
PictureBox1.Width = Panel1.PointToClient(Panel1.MousePosition).X - Panel1.AutoScrollPosition.X
Case "resizeDR"
PictureBox1.Width = Panel1.PointToClient(Panel1.MousePosition).X - Panel1.AutoScrollPosition.X
PictureBox1.Height = Panel1.PointToClient(Panel1.MousePosition).Y - Panel1.AutoScrollPosition.Y
End Select

redrawGrabPoints()

End If
End Sub

Private Sub redrawGrabPoints()
Dim offset As Integer = 5
Dim tempPoint As System.Drawing.Point

tempPoint = New System.Drawing.Point(PictureBox1.Width + offset, 1)
tempPoint.Offset(Panel1.AutoScrollPosition.X, Panel1.AutoScrollPosition.Y)
resizeUR.Location = tempPoint

tempPoint = New System.Drawing.Point(1, PictureBox1.Height + offset)
temppoint.Offset(Panel1.AutoScrollPosition.X, Panel1.AutoScrollPosition.Y)
resizeDL.Location = temppoint

temppoint = New System.Drawing.Point(PictureBox1.Width + offset, PictureBox1.Height + offset)
temppoint.Offset(Panel1.AutoScrollPosition.X, Panel1.AutoScrollPosition.Y)
resizeDR.Location = temppoint

tempPoint = New System.Drawing.Point(CInt(PictureBox1.Width / 2), PictureBox1.Height + offset)
temppoint.Offset(Panel1.AutoScrollPosition.X, Panel1.AutoScrollPosition.Y)
resizeD.Location = temppoint

tempPoint = New System.Drawing.Point(CInt(PictureBox1.Width / 2), 1)
temppoint.Offset(Panel1.AutoScrollPosition.X, Panel1.AutoScrollPosition.Y)
resizeU.Location = temppoint

tempPoint = New System.Drawing.Point(1, CInt(PictureBox1.Height / 2))
temppoint.Offset(Panel1.AutoScrollPosition.X, Panel1.AutoScrollPosition.Y)
resizeL.Location = temppoint

tempPoint = New System.Drawing.Point(PictureBox1.Width + offset, CInt(PictureBox1.Height / 2))
temppoint.Offset(Panel1.AutoScrollPosition.X, Panel1.AutoScrollPosition.Y)
resizeR.Location = temppoint
 

Attachments

  • ImageEditor.zip
    33.9 KB · Views: 70
Although the mouse remains stationary, the mouse position with reference to the top and left of the control keeps changing in the scrolling viewport. That is because you resize the picturebox as soon as the mouse moves. Try drawing an outline instead and resize the box finally when mouse up. You can also draw the image itself - but do not resize the picturebox on mousemove
 
Back
Top