The project goal is to rotate the middle disk(RaobfMobile Picturebox)) backward into the in-outer disk(RaobfBG(PictureBox)) accordingly to the mouse location (holding left button) in order to read a result (red line) on a graduation circle.
This middle disk should stay backward of the in-out one in order to keep red lines over it and show a result on graduation. It must keep his initial center(470 :470) to rotate.
Video Drive link=> Raobf Project Video Clip (28s)
- Issue 1 (1s => 18s)
How to keep correct disc center when moving the mifddle disc (noticeable in VideoClip). I thought code : Private picRCenter As New Point(470, 470) would do that.
- Issue 2 (19s => video end)
When releasing left button, i lose mouse control on middle disc and can't move the middle disc anymore. Code : Using RaobfMobile.Capture = true in Form1_Load is not enough to trigger MouseMove event more than once.
- Question :
Is it possible to define circle (instead of rectangle) Picturebox ? maybe more convenient to avoid center shift.
Note : - I will clear picture sources in final dev phase. - Sry for my average english wording.
Help would be greatly appreciated.
Public Class Form1
Private WithEvents RaobfMobile As New PictureBox With {.Parent = Me, .Cursor = Cursors.Hand,
.BackgroundImageLayout = ImageLayout.Center,
.BackgroundImage = Image.FromFile("C:\Users\Grimsek\Documents\Wolfpack documentation\RAOBF Prj\RAOBFInner_transp.png"),
.Location = New Point(0, 0), .Size = New Size(940, 940),
.BackColor = Color.SteelBlue}
Private WithEvents RaobfBG As New PictureBox With {.Parent = Me,
.BackgroundImageLayout = ImageLayout.Center,
.BackgroundImage = Image.FromFile("C:\Users\Grimsek\Documents\Wolfpack documentation\RAOBF Prj\RAOBFOuter_transp.png"),
.Location = New Point(0, 0), .Size = New Size(940, 940),
.BackColor = Color.SteelBlue}
Private picRSize As New Size(940, 940)
Private picRCenter As New Point(470, 470)
Private angle As Double = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
RaobfMobile.Controls.Add(RaobfBG)
RaobfBG.Location = New Point(0, 0)
RaobfBG.BackColor = Color.Transparent
Text = "Rotation RAOBF"
ClientSize = New Size(940, 940)
DoubleBuffered = True
SetRotated(RaobfMobile, CSng(angle))
RaobfMobile.Capture = True
End Sub
Private Function GetAngle(ByVal ptFrom As PointF, ByVal ptTo As PointF) As Double
Dim dx As Double = ptFrom.X - ptTo.X
Dim dy As Double = ptFrom.Y - ptTo.Y
Dim a As Double = 57.3 * Math.Atan2(dy, dx)
If a > 360 Then angle -= 360
If a < 0 Then angle += 360
Return a
End Function
Private Sub picR_MouseMove(sender As Object, e As MouseEventArgs) Handles RaobfMobile.MouseMove
If e.Button = MouseButtons.Left Then
angle = GetAngle(e.Location, New Point(CInt(RaobfMobile.Bounds.Width / 2),
CInt(RaobfMobile.Bounds.Height / 2)))
SetRotated(RaobfMobile, CSng(angle))
Refresh()
End If
End Sub
Private Sub picR_Paint(sender As Object, e As PaintEventArgs) Handles RaobfMobile.Paint
'draw the rotated image
Using mx As New Matrix
mx.RotateAt(CSng(angle), New PointF(CSng(RaobfMobile.ClientSize.Width / 2), CSng(RaobfMobile.ClientSize.Height / 2)))
e.Graphics.Transform = mx
Dim x As Integer = CInt((RaobfMobile.ClientSize.Width / 2) - (RaobfMobile.BackgroundImage.Width / 2))
Dim y As Integer = CInt((RaobfMobile.ClientSize.Height / 2) - (RaobfMobile.BackgroundImage.Height / 2))
e.Graphics.DrawImage(RaobfMobile.BackgroundImage, x, y,
RaobfMobile.BackgroundImage.Width, RaobfMobile.BackgroundImage.Height)
End Using
End Sub
Private Sub SetRotated(thePic As PictureBox, angle As Single)
Using rg As New Region,
mx As New Matrix,
pth As New GraphicsPath
'get the size of the rotated rect
pth.AddRectangle(New RectangleF(0, 0, picRSize.Width, picRSize.Height))
mx.RotateAt(angle, New PointF(CSng(picRSize.Width / 2), CSng(picRSize.Height / 2)))
pth.Transform(mx)
Dim rect As RectangleF = pth.GetBounds()
'size the pict to fit the rect
thePic.ClientSize = New Size(CInt(rect.Width + 1), CInt(rect.Height + 1))
thePic.Location = New Point(CInt(picRCenter.X - thePic.ClientSize.Width / 2), CInt(picRCenter.Y - thePic.ClientSize.Height / 2))
'remake the path rect at the new pic center and rotate
pth.Reset()
Dim x1 As Integer = CInt((thePic.ClientSize.Width / 2) - (picRSize.Width / 2))
Dim y1 As Integer = CInt((thePic.ClientSize.Height / 2) - (picRSize.Height / 2))
pth.AddRectangle(New RectangleF(x1, y1, picRSize.Width, picRSize.Height))
mx.Reset()
mx.RotateAt(angle, New PointF(CSng(thePic.ClientSize.Width / 2), CSng(thePic.ClientSize.Height / 2)))
pth.Transform(mx)
'add rotated path region to picturebox
thePic.Region = New Region(pth)
End Using
End Sub
End Class