投稿者 あにす  (社会人) 投稿日時 2009/12/9 05:30:59
    Private Sub PictureBox1_MouseMove(ByVal sender As ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles _
                    PictureBox1.MouseMove, PictureBox2.MouseMove, PictureBox3.MouseMove, PictureBox4.MouseMove, _
                     PictureBox5.MouseMove, PictureBox6.MouseMove, PictureBox7.MouseMove, PictureBox8.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Dim diffX As Integer = e.X - MousePoint.X
            Dim diffY As Integer = e.Y - MousePoint.Y

            Select Case Me.senderPictureBox.Name
                Case "PictureBox1" '左上 
                    Dim w As Integer = Me.Width
                    Me.Width -= diffX
                    Me.Left += w - Me.Width

                    Dim h As Integer = Me.Height
                    Me.Height -= diffY
                    Me.Top += h - Me.Height
                Case "PictureBox2" '上 
                    Dim h As Integer = Me.Height
                    Me.Height -= diffY
                    Me.Top += h - Me.Height
                Case "PictureBox3" '右上 
                    Me.Width = MouseDownSize.Width + diffX

                    Dim h As Integer = Me.Height
                    Me.Height -= diffY
                    Me.Top += h - Me.Height
                Case "PictureBox4" '左 
                    Dim w As Integer = Me.Width
                    Me.Width -= diffX
                    Me.Left += w - Me.Width
                Case "PictureBox5" '右 
                    Me.Width = MouseDownSize.Width + diffX
                Case "PictureBox6" '左下 
                    Dim w As Integer = Me.Width
                    Me.Width -= diffX
                    Me.Left += w - Me.Width

                    Me.Height = MouseDownSize.Height + diffY
                Case "PictureBox7" '下 
                    Me.Height = MouseDownSize.Height + diffY
                Case "PictureBox8" '右下 
                    Me.Width = MouseDownSize.Width + diffX

                    Me.Height = MouseDownSize.Height + diffY
            End Select
            Me.Refresh()
        End If
    End Sub

    Private Sub PictureBox1_MouseUp(ByVal sender As ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles _
                    PictureBox1.MouseUp, PictureBox2.MouseUp, PictureBox3.MouseUp, PictureBox4.MouseUp, _
                     PictureBox5.MouseUp, PictureBox6.MouseUp, PictureBox7.MouseUp, PictureBox8.MouseUp, MyBase.MouseUp
        Call HandleHide(False) : Call CtrlSyoki()
    End Sub

    Private Sub HandleHide(ByVal TF As Boolean)
        For Each c As Control In Me.Controls
            If 0 < InStr(c.Name, "PictureBox"Then
                c.Visible = Not TF
            End If
        Next
    End Sub
End Class