Option Strict Off
Imports System.Data.SqlClient
Imports System.IO
Public Class 驗貨報告大圖
    Dim conn As New SqlConnection
    Dim cmd As New SqlCommand
    Dim dr As SqlDataReader
    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  'ControlBox = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT TOP(1) 驗貨報告 FROM 驗貨報告圖庫 WHERE 驗貨報告編號 LIKE '" & 驗貨報告 & "'"
        cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
        PictureBox1.Image = Nothing
        While dr.Read() = True
            Dim bytes As Byte() = New Byte(-1) {} : bytes = DirectCast(dr.Item("驗貨報告"), Byte()) : Dim oStream As New MemoryStream(bytes)
            PictureBox1.Image = Bitmap.FromStream(oStream)
        End While
        conn.Close() : PictureBox1.SizeMode = 4
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        PictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        PictureBox1.Image.RotateFlip(RotateFlipType.Rotate270FlipNone) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
    End Sub
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        PictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipY) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
    End Sub
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        PictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipX) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
    End Sub
    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Dim image = PictureBox1.Image
        Dim g As Graphics = PictureBox1.CreateGraphics
        g.DrawImage(image, New Rectangle(0, 0, image.Width * 1.01, image.Height * 1.01))
        image = Nothing
    End Sub
    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        PictureBox1.Refresh()
    End Sub
    '@#处理鼠标按键抬起的事件，根据鼠标按下时保存的鼠标位置，和当前鼠标的位置， 
    '计算鼠标移动偏移量，借此调用移动图片的函数，移动图片 
    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseUp
        m_DeltaX = m_MousePosX - e.X
        m_DeltaY = m_MousePosY - e.Y
        m_Leftx = m_Leftx - m_DeltaX
        m_Lefty = m_Lefty - m_DeltaY
        Picturemove(sender, e)
        Me.Cursor = Cursors.Arrow
    End Sub
    '@#当鼠标按下时，将鼠标变成手形，并且记录下当前鼠标的位置 
    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.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(PictureBox1.Image)
        Dim myPicGrh As Graphics = Me.PictureBox1.CreateGraphics
        myPicGrh.Clear(Me.PictureBox1.BackColor)
        myPicGrh.DrawImageUnscaled(myBit, m_Leftx - 152, m_Lefty)
        myBit.Dispose()
        myPicGrh.Dispose()
    End Sub
End Class