Option Strict On disallows implicit conversions from 'System.Drawing.Point' to 'System.Drawing.Size'

547 Views Asked by At

After i tried to optimize my code with option Strict ON i get many errors at least one is left.

i've created the Variable MoveForm_MousePosition as Point = System.drawing.point

    Imports System.Drawing
    Public MoveForm_MousePosition As Point

Private Sub lblYaple_MouseDown(sender As Object, e As MouseEventArgs) Handles lblYaple.MouseDown
        If e.Button = MouseButtons.Left Then
            MoveForm = True
            Me.Cursor = Cursors.NoMove2D
            MoveForm_MousePosition = e.Location
        End If
    End Sub
    Public Sub lblYaple_MouseMove(sender As Object, e As MouseEventArgs) Handles lblYaple.MouseMove
        If MoveForm Then Me.Location = Me.Location + (e.Location - MoveForm_MousePosition)
    End Sub

In this Line

If MoveForm Then Me.Location = Me.Location + (e.Location - MoveForm_MousePosition)

Option Strict On disallows implicit conversions from 'System.Drawing.Point' to 'System.Drawing.Size'

can't understand, me.location and e.location and MoveForm_MousePostions should be System.Drawing.Point why comes this error up?

1

There are 1 best solutions below

1
On

As you can see from the MSDN documents the RHS parameter type of the point subtraction operator is Size.

'LHS (point)  RHS (size)
(e.Location - MoveForm_MousePosition)

And as observed, you cannot convert a point structure to a size structure. So one way to fix this is to create a new point structure like this:

Me.Location = New Point(
    (Me.Location.X + (e.Location.X - MoveForm_MousePosition.X)),
    (Me.Location.Y + (e.Location.Y - MoveForm_MousePosition.Y))
)