Option Strict Off
Public Class 採購訂製大圖
    Private m_Leftx As Integer = 152
    Private m_Lefty As Integer = 0
    Dim m_MousePosX As Integer
    Dim m_MousePosY As Integer
    Dim m_DeltaX As Integer
    Dim m_DeltaY As Integer
    Private Sub 採購訂製大圖_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        FormBorderStyle = FormBorderStyle.SizableToolWindow

        If YD_ERP_SYS.Size.Width > 1900 Then : Me.Size = New Size(1760, 850) : Me.Location = New Point(100, 50)
        ElseIf YD_ERP_SYS.Size.Width > 1800 Then : Me.Size = New Size(1660, 800) : Me.Location = New Point(100, 50)
        ElseIf YD_ERP_SYS.Size.Width > 1600 Then : Me.Size = New Size(1560, 750) : Me.Location = New Point(100, 50)
        ElseIf YD_ERP_SYS.Size.Width > 1500 Then : Me.Size = New Size(1460, 700) : Me.Location = New Point(100, 50)
        ElseIf YD_ERP_SYS.Size.Width > 1400 Then : Me.Size = New Size(1360, 650) : Me.Location = New Point(100, 50)
        ElseIf YD_ERP_SYS.Size.Width > 1300 Then : Me.Size = New Size(1260, 600) : Me.Location = New Point(100, 50)
        End If

        SQL_採購控制表_訂製圖片()
        訂製圖_pb.Image = Nothing
        While dr.Read() = True
            Dim unused As Byte() = New Byte(-1) {} : Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
            Dim oStream As New MemoryStream(bytes)
            訂製圖_pb.Image = Bitmap.FromStream(oStream)
        End While
        conn.Close() : 訂製圖_pb.SizeMode = 4
    End Sub
    Private Sub 順時鐘90_bt_Click(sender As Object, e As EventArgs) Handles 順時鐘90_bt.Click
        訂製圖_pb.Image.RotateFlip(RotateFlipType.Rotate90FlipNone) : 訂製圖_pb.Refresh() : 訂製圖_pb.SizeMode = 4
    End Sub
    Private Sub 逆時鐘90_bt_Click(sender As Object, e As EventArgs) Handles 逆時鐘90_bt.Click
        訂製圖_pb.Image.RotateFlip(RotateFlipType.Rotate270FlipNone) : 訂製圖_pb.Refresh() : 訂製圖_pb.SizeMode = 4
    End Sub
    Private Sub 水平翻轉_bt_Click(sender As Object, e As EventArgs) Handles 水平翻轉_bt.Click
        訂製圖_pb.Image.RotateFlip(RotateFlipType.Rotate180FlipY) : 訂製圖_pb.Refresh() : 訂製圖_pb.SizeMode = 4
    End Sub
    Private Sub 垂直翻轉_bt_Click(sender As Object, e As EventArgs) Handles 垂直翻轉_bt.Click
        訂製圖_pb.Image.RotateFlip(RotateFlipType.Rotate180FlipX) : 訂製圖_pb.Refresh() : 訂製圖_pb.SizeMode = 4
    End Sub
    Private Sub 放大_bt_Click(sender As Object, e As EventArgs) Handles 放大_bt.Click
        Dim image = 訂製圖_pb.Image
        Dim g As Graphics = 訂製圖_pb.CreateGraphics
        g.DrawImage(image, New Rectangle(0, 0, image.Width * 1.01, image.Height * 1.01))
    End Sub
    Private Sub 復原_bt_Click(sender As Object, e As EventArgs) Handles 復原_bt.Click
        訂製圖_pb.Refresh()
    End Sub
    '@#处理鼠标按键抬起的事件，根据鼠标按下时保存的鼠标位置，和当前鼠标的位置， 
    '计算鼠标移动偏移量，借此调用移动图片的函数，移动图片 
    Private Sub 訂製圖_pb_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles 訂製圖_pb.MouseUp
        m_DeltaX = m_MousePosX - e.X
        m_DeltaY = m_MousePosY - e.Y
        m_Leftx -= m_DeltaX
        m_Lefty -= m_DeltaY
        Picturemove(sender, e)
        Me.Cursor = Cursors.Arrow
    End Sub
    '@#当鼠标按下时，将鼠标变成手形，并且记录下当前鼠标的位置 
    Private Sub 訂製圖_pb_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles 訂製圖_pb.MouseDown
        Me.Cursor = Cursors.Hand
        m_MousePosX = e.X
        m_MousePosY = e.Y
    End Sub
    '@#根据偏移量计算出的图片位置，重画图片 
    Private Sub Picturemove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim myBit As New Bitmap(訂製圖_pb.Image)
        Dim myPicGrh As Graphics = Me.訂製圖_pb.CreateGraphics
        myPicGrh.Clear(Me.訂製圖_pb.BackColor)
        myPicGrh.DrawImageUnscaled(myBit, m_Leftx - 152, m_Lefty)
        myBit.Dispose()
        myPicGrh.Dispose()
    End Sub
End Class