投稿者 モル  (社会人) 投稿日時 2009/12/9 00:02:30
サンプル(長いですが)
新しいプロジェクト→クラスライブラリ→プロジェクト→ユーザーコントロールの追加
UserControl1の上にPictureBoxを8個配置。
Imports System.Drawing
Imports System.Windows.Forms

Public Class UserControl1
    Private MousePoint As Point

    Private Sub FCHandle_UC_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load
        Call CtrlSyoki()
    End Sub

    Private Sub CtrlSyoki()
        Me.BackColor = Color.Black
        For Each c As Control In Me.Controls
            If 0 < InStr(c.Name, "PictureBox"Then
                c.Width = 10 : c.Height = 10 : c.BackColor = Color.Yellow
            End If
        Next

        With PictureBox1
            .Left = 0 : .Top = 0
        End With
        With PictureBox2
            .Left = Me.Width / 2 - .Width / 2 : .Top = 0
        End With
        With PictureBox3
            .Left = Me.Width - .Width : .Top = 0
        End With

        With PictureBox4
            .Left = 0 : .Top = Me.Height / 2 - .Height / 2
        End With
        With PictureBox5
            .Left = Me.Width - .Width : .Top = Me.Height / 2 - .Height / 2
        End With

        With PictureBox6
            .Left = 0 : .Top = Me.Height - .Height
        End With
        With PictureBox7
            .Left = Me.Width / 2 - .Width / 2 : .Top = Me.Height - .Height
        End With
        With PictureBox8
            .Left = Me.Width - .Width : .Top = Me.Height - .Height
        End With
    End Sub

    Private Sub PictureBox1_MouseDown(ByVal sender As ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles _
                    PictureBox1.MouseDown, PictureBox2.MouseDown, PictureBox3.MouseDown, PictureBox4.MouseDown, _
                     PictureBox5.MouseDown, PictureBox6.MouseDown, PictureBox7.MouseDown, PictureBox8.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            MousePoint = New Point(e.X, e.Y) : Call HandleHide(True)
        End If
    End Sub

    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
            sender.left += e.X - MousePoint.X : sender.top += e.Y - MousePoint.Y
            Select Case sender.name
                Case "PictureBox1"

                Case "PictureBox2"

                Case "PictureBox3"

                Case "PictureBox4"

                Case "PictureBox5"
                    Me.Width = sender.left + sender.width
                Case "PictureBox6"

                Case "PictureBox7"
                    Me.Height = sender.top + sender.height
                Case "PictureBox8"
                    Me.Width = sender.left + sender.width : Me.Height = sender.top + sender.height
            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
        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