Option Strict On禁止来自' System.Drawing.Point'的隐式转换。到' System.Drawing.Size'

时间:2015-01-04 11:08:05

标签: vb.net option strict

在我尝试使用选项Strict ON优化我的代码后,我得到很多错误,至少剩下一个。

我已将变量 MoveForm_MousePosition创建为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

在这一行

如果MoveForm然后Me.Location = Me.Location +(e.Location - MoveForm_MousePosition

  

Option Strict On禁止从'System.Drawing.Point'到'System.Drawing.Size'的隐式转换

无法理解,me.location和e.location以及MoveForm_MousePostions应该是 System.Drawing.Point为什么会出现这个错误?

1 个答案:

答案 0 :(得分:2)

MSDN documents可以看出,点减法运算符的RHS参数类型为Size

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

如上所述,您无法将点结构转换为大小结构。所以解决这个问题的一种方法是创建一个像这样的新点结构:

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