I hope you can help me.
Event MouseDown
<pre> Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
Me._mousePositionMove = e.Location
If e.Button = MouseButtons.Left Then
If Not Me._mousePress = True Then
Me._mousePress = True
Me._mouseDown_Location = e.Location
Me._TraslationX_Graphics_old = Me._TraslationX_Graphics
Me._TraslationY_Graphics_old = Me._TraslationY_Graphics
IsZoomPan_MouseEvent = True
IsFitDrawingToControl_ClikButtonEvent = False
End If
End If
LineasReferenciaMouse_Dibujar = True
Me.Invalidate()
MyBase.OnMouseDown(e)
End Sub
Event MouseMove
Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
Me._mousePositionMove = e.Location
If e.Button = MouseButtons.Left Then
Me.Cursor = Cursors.SizeAll
Dim mousePosNow As PointF = e.Location
Dim deltaX, deltaY As Single
deltaX = mousePosNow.X - Me._mouseDown_Location.X
deltaY = (mousePosNow.Y - Me._mouseDown_Location.Y) * -1
Me._TraslationX_Graphics = (Me._TraslationX_Graphics_old + (deltaX / Me._zoom))
Me._TraslationY_Graphics = (Me._TraslationY_Graphics_old + (deltaY / Me._zoom))
IsZoomPan_MouseEvent = True
IsFitDrawingToControl_ClikButtonEvent = False
End If
LineasReferenciaMouse_Dibujar = True
Me.Invalidate()
MyBase.OnMouseMove(e)
End Sub
Evento MouseWheel
<pre> Protected Overrides Sub OnMouseWheel(e As MouseEventArgs)
Me._zoom_old = Me._zoom
If e.Delta > 0 Then
Me._zoom = Math.Min((Me._zoom + _zoom_increment), _zoom_max)
Else
Me._zoom = Math.Max((Me._zoom - _zoom_increment), _zoom_min)
End If
Dim mousePosNow As PointF = e.Location
Dim deltaX, deltaY As Single
deltaX = mousePosNow.X - 0
deltaY = Me.ClientRectangle.Height - mousePosNow.Y - 0
Dim oldGraphicsX As Single
Dim oldGraphicsY As Single
oldGraphicsX = ((deltaX / Me._zoom_old))
oldGraphicsY = ((deltaY / Me._zoom_old))
Dim newGraphicsX As Single
Dim newGraphicsY As Single
newGraphicsX = ((deltaX / Me._zoom))
newGraphicsY = ((deltaY / Me._zoom))
Me._TraslationX_Graphics = newGraphicsX - oldGraphicsX + Me._TraslationX_Graphics
Me._TraslationY_Graphics = newGraphicsY - oldGraphicsY + Me._TraslationY_Graphics
Me._mousePositionMove = mousePosNow
IsZoomPan_MouseEvent = True
LineasReferenciaMouse_Dibujar = True
IsFitDrawingToControl_ClikButtonEvent = False
Invalidate()
MyBase.OnMouseWheel(e)
End Sub
Event Paint
Protected Overrides Sub OnPaint(e As PaintEventArgs)
Me._graphicsControl = e.Graphics
Me._graphicsControl.Clear(GraphicsControl_ClearColor)
Me._graphicsControl.SmoothingMode = If(Me.GraphicsControl_CalidadDibujo = SmoothingMode.Invalid, SmoothingMode.AntiAlias, Me. GraphicsControl_CalidadDibujo)
If Me.EjesGlobales_Dibujar = True Then
Transforms the axes of the graph with its origin in the lower left part of the control and with the AXIS pointing upwards (positive)
TransformarEjesGlobalesGraphics(Me._graphicsControl, Me.ClientRectangle.Height)
Me.DibujarEjesControl()
End If
If Me.LineasReferenciaMouse_Dibujar = True Then
TransformarEjesGlobalesGraphics(Me._graphicsControl, Me.ClientRectangle.Height)
Me._graphicsControl.ScaleTransform(Me._zoom, _zoom)
Me._graphicsControl.TranslateTransform(Me._TraslationX_Graphics, Me._TraslationY_Graphics)
DibujarLineasReferenciaMouse(Me._mousePositionMove, Me._graphicsControl)
End If
Dim myzapata As New MyDrawings.ZapataPlanta(2.5D, 3.5D, e.Graphics) With {
.Contorno_Color = Color.DarkRed,
.Contorno_GrosorPen = 0.8D,
.Relleno_Color = Color.DarkBlue,
.Relleno_ColorTransparencia = 25
}
Dim myPath As GraphicsPath = myzapata.GraphicsPath_Dibujo
Dim myPointsAll As PointF() = myPath.PathPoints
Dim centerControl As New PointF With {
.X = (ClientRectangle.Left + ClientRectangle.Right) / 2.0F,
.Y = (ClientRectangle.Bottom + ClientRectangle.Top) / 2.0F
}
If Me.IsFitDrawingToControl_ClikButtonEvent = True Then
TransformarEjesGlobalesGraphics(Me._graphicsControl, Me.ClientRectangle.Height)
_graphicsControl.TransformPoints(CoordinateSpace.Page, CoordinateSpace.World, myPointsAll)
Dim centerDibujo As New PointF With {
.X = (myPointsAll.Min(Function(x) x.X) + myPointsAll.Max(Function(x) x.X)) / 2.0F,
.Y = (myPointsAll.Min(Function(y) y.Y) + myPointsAll.Max(Function(y) y.Y)) / 2.0F
}
_graphicsControl.TranslateTransform(-centerDibujo.X, -centerDibujo.Y, MatrixOrder.Append)
Dim scaleRatioPage As Single
scaleRatioPage = Math.Min((ClientRectangle.Width - 30) / myPath.GetBounds.Width, (ClientRectangle.Height - 30) / myPath.GetBounds.Height)
_graphicsControl.ScaleTransform(scaleRatioPage, scaleRatioPage, MatrixOrder.Append)
_graphicsControl.TranslateTransform(centerControl.X, centerControl.Y, MatrixOrder.Append)
_graphicsControl.FillPath(myzapata.Brush_RellenoZapata, myPath)
_graphicsControl.DrawPath(myzapata.Pen_ContornoZapata(CDec(scaleRatioPage)), myPath)
ElseIf Me.IsZoomPan_MouseEvent = True Then
TransformarEjesGlobalesGraphics(Me._graphicsControl, Me.ClientRectangle.Height)
Dim scaleRatioPage As Single
scaleRatioPage = Math.Min((ClientRectangle.Width - 30) / myPath.GetBounds.Width, (ClientRectangle.Height - 30) / myPath.GetBounds.Height)
_graphicsControl.TranslateTransform(Me._TraslationX_Graphics * _zoom, Me._TraslationY_Graphics * _zoom)
_graphicsControl.ScaleTransform(scaleRatioPage * _zoom, scaleRatioPage * _zoom)
_graphicsControl.FillPath(myzapata.Brush_RellenoZapata, myPath)
_graphicsControl.DrawPath(myzapata.Pen_ContornoZapata(CDec(scaleRatioPage * _zoom)), myPath)
End If
MyBase.OnPaint(e)
End Sub