Option Strict Off
Option Explicit On
'------------------------------------ 2024/04/01 ------------------------------------
Public Class 五clsWakuwaku

#Region "Private 変数および定数"

    Private Const cOutSizeMin As Integer = 10, cOutSizeMax As Integer = 4000
    Private Const cLineSizeMin As Integer = 2, cLineSizeMax As Integer = 1000
    Private mBar() As Label = {Nothing, Nothing, Nothing, Nothing}
    Private mColor As Color = Color.Blue
    Private mLineWD As Integer = 3
    Private mWidth As Integer = 100
    Private mHeight As Integer = 100
    Private mLeft As Integer = 100
    Private mTop As Integer = 100

#End Region

#Region "初期化 *******************************************************************"

    Friend Function aa_Make(ByVal rParent As Control, ByVal rLineWD As Integer, ByVal rLineColor As Color) As Boolean
        If mBar(0) IsNot Nothing Then Return False
        gggbol = zzNewLabelMake(rParent, mBar(0), rLineColor)
        gggbol = zzNewLabelMake(rParent, mBar(1), rLineColor)
        gggbol = zzNewLabelMake(rParent, mBar(2), rLineColor)
        gggbol = zzNewLabelMake(rParent, mBar(3), rLineColor)
        LineWidth = rLineWD
        CurColor = rLineColor
        For a As Integer = 0 To 3 : mBar(a).Enabled = False : Next
        Return True
    End Function

    Friend Function aa_Delete() As Boolean
        If mBar(0) Is Nothing Then Return False
        mBar(0).Dispose() : mBar(0) = Nothing
        mBar(1).Dispose() : mBar(1) = Nothing
        mBar(2).Dispose() : mBar(2) = Nothing
        mBar(3).Dispose() : mBar(3) = Nothing
        Return True
    End Function

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub

#End Region

#Region "関数 *********************************************************************"

    Private Function zzNewLabelMake(ByVal rParent As Control, ByRef lbl As Label, ByVal rLineColor As Color) As Boolean
        lbl = New Label
        With lbl
            .BorderStyle = BorderStyle.None
            .SetBounds(0, 0, 30, 30)
            .Text = ""
            .BackColor = rLineColor
            .AutoSize = False
            .Parent = rParent
        End With
        Return True
    End Function

    Friend Function aa_BringToFront() As Boolean
        If mBar(3) Is Nothing Then Return False
        For a As Integer = 0 To 3
            mBar(a).BringToFront()
        Next
        Return True
    End Function

    Friend Function aa_位置サイズ_Set(ByVal 左 As Integer, ByVal 上 As Integer, ByVal 幅 As Integer, ByVal 高 As Integer, Optional ByVal r特別なライン幅 As Integer = 0) As Boolean
        If mBar(3) Is Nothing Then Return False
        Dim ww As Integer = r特別なライン幅
        If ww < 1 Or ww > 幅 \ 2 Or ww > 高 \ 2 Then ww = mLineWD
        Dim ww2 As Integer = ww * 2
        Dim 幅幅 As Integer = IIf(幅 < ww2, ww2, 幅)
        Dim 高高 As Integer = IIf(高 < ww2, ww2, 高)
        Dim 左左 As Integer = 左
        Dim 上上 As Integer = 上
        Dim x0, x1, x2, x3, y0, y1, y2, y3 As Integer
        x0 = 左左
        x3 = 左左 + 幅幅
        x1 = x0 + ww
        x2 = x3 - ww
        y0 = 上上
        y3 = 上上 + 高高
        y1 = y0 + ww
        y2 = y3 - ww
        Try
            mBar(0).SetBounds(x0, y0, 幅幅, ww)
            mBar(1).SetBounds(x2, y0, ww, 高高)
            mBar(2).SetBounds(x0, y2, 幅幅, ww)
            mBar(3).SetBounds(x0, y0, ww, 高高)
        Catch ex As Exception
        End Try
        Return True
    End Function

    Friend Function aa_位置サイズ_Get(ByRef 左 As Integer, ByRef 上 As Integer, ByRef 幅 As Integer, ByRef 高 As Integer) As Boolean
        If mBar(3) Is Nothing Then Return False
        左 = mBar(0).Left
        上 = mBar(0).Top
        幅 = mBar(0).Width
        高 = mBar(1).Height
        Return True
    End Function

#End Region

#Region "プロパティ*****************************************************************"

    Friend ReadOnly Property Left() As Integer
        Get
            Return mBar(0).Left
        End Get
    End Property

    Friend ReadOnly Property Top() As Integer
        Get
            Return mBar(0).Top
        End Get
    End Property

    Friend ReadOnly Property Width() As Integer
        Get
            Return mBar(0).Width
        End Get
    End Property

    Friend ReadOnly Property Height() As Integer
        Get
            Return mBar(1).Height
        End Get
    End Property

    Friend Property Visible() As Boolean
        Get
            If mBar(3) IsNot Nothing Then Return mBar(3).Visible
            Return False
        End Get
        Set(ByVal value As Boolean)
            If mBar(3) IsNot Nothing Then
                For a As Integer = 0 To 3 : mBar(a).Visible = value : Next
            End If
        End Set
    End Property

    Friend Property LineWidth() As Integer
        Get
            Return mLineWD
        End Get
        Set(ByVal value As Integer)
            mLineWD = Math.Max(cLineSizeMin, Math.Min(cLineSizeMax, value))
        End Set
    End Property

    Friend Property CurColor() As Color
        Get
            Return mColor
        End Get
        Set(ByVal value As Color)
            mColor = value
            If mBar(3) IsNot Nothing Then
                For a As Integer = 0 To 3 : mBar(a).BackColor = mColor : Next
            End If
        End Set
    End Property

#End Region

End Class
