Point类源代码

Imports System
Imports System.ComponentModel
Imports System.Globalization
Imports System.Runtime.InteropServices

Namespace System.Drawing
    <Serializable, StructLayout(LayoutKind.Sequential), TypeConverter(GetType(PointConverter)), ComVisible(True)> _
    Public Structure Point
        Public Shared ReadOnly Empty As Point
        Private x As Integer
        Private y As Integer
        Public Sub New(ByVal x As Integer, ByVal y As Integer)
            Me.x = x
            Me.y = y
        End Sub

        Public Sub New(ByVal sz As Size)
            Me.x = sz.Width
            Me.y = sz.Height
        End Sub

        Public Sub New(ByVal dw As Integer)
            Me.x = CShort(Point.LOWORD(dw))
            Me.y = CShort(Point.HIWORD(dw))
        End Sub

        <Browsable(False)> _
        Public ReadOnly Property IsEmpty As Boolean
            Get
                Return ((Me.x = 0) AndAlso (Me.y = 0))
            End Get
        End Property

        Public Property X As Integer
            Get
                Return Me.x
            End Get
            Set(ByVal value As Integer)
                Me.x = value
            End Set
        End Property

        Public Property Y As Integer
            Get
                Return Me.y
            End Get
            Set(ByVal value As Integer)
                Me.y = value
            End Set
        End Property

        Public Shared [Widening] [Operator] CType(ByVal p As Point) As PointF
            Return New PointF(CSng(p.X), CSng(p.Y))
        End Function

        Public Shared [Narrowing] [Operator] CType(ByVal p As Point) As Size
            Return New Size(p.X, p.Y)
        End Function

        Public Shared [Operator] +(ByVal pt As Point, ByVal sz As Size) As Point
            Return Point.Add(pt, sz)
        End Function

        Public Shared [Operator] -(ByVal pt As Point, ByVal sz As Size) As Point
            Return Point.Subtract(pt, sz)
        End Function

        Public Shared [Operator] =(ByVal left As Point, ByVal right As Point) As Boolean
            Return ((left.X = right.X) AndAlso (left.Y = right.Y))
        End Function

        Public Shared [Operator] <>(ByVal left As Point, ByVal right As Point) As Boolean
            Return Not (left = right)
        End Function

        Public Shared Function Add(ByVal pt As Point, ByVal sz As Size) As Point
            Return New Point((pt.X + sz.Width), (pt.Y + sz.Height))
        End Function

        Public Shared Function Subtract(ByVal pt As Point, ByVal sz As Size) As Point
            Return New Point((pt.X - sz.Width), (pt.Y - sz.Height))
        End Function

        Public Shared Function Ceiling(ByVal value As PointF) As Point
            Return New Point(CInt(Math.Ceiling(CDbl(value.X))), CInt(Math.Ceiling(CDbl(value.Y))))
        End Function

        Public Shared Function Truncate(ByVal value As PointF) As Point
            Return New Point(CInt(value.X), CInt(value.Y))
        End Function

        Public Shared Function Round(ByVal value As PointF) As Point
            Return New Point(CInt(Math.Round(CDbl(value.X))), CInt(Math.Round(CDbl(value.Y))))
        End Function

        Public Overrides Function Equals(ByVal obj As Object) As Boolean
            If Not TypeOf obj Is Point Then
                Return False
            End If
            Dim point As Point = DirectCast(obj, Point)
            Return ((point.X = Me.X) AndAlso (point.Y = Me.Y))
        End Function

        Public Overrides Function GetHashCode() As Integer
            Return (Me.x Xor Me.y)
        End Function

        Public Sub Offset(ByVal dx As Integer, ByVal dy As Integer)
            Me.X = (Me.X + dx)
            Me.Y = (Me.Y + dy)
        End Sub

        Public Sub Offset(ByVal p As Point)
            Me.Offset(p.X, p.Y)
        End Sub

        Public Overrides Function ToString() As String
            Return String.Concat(New String() { "{X=", Me.X.ToString(CultureInfo.CurrentCulture), ",Y=", Me.Y.ToString(CultureInfo.CurrentCulture), "}" })
        End Function

        Private Shared Function HIWORD(ByVal n As Integer) As Integer
            Return ((n >> &H10) And &HFFFF)
        End Function

        Private Shared Function LOWORD(ByVal n As Integer) As Integer
            Return (n And &HFFFF)
        End Function

        Shared Sub New()
            Point.Empty = New Point
        End Sub
    End Structure
End Namespace

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值