Option Strict Off
Option Explicit On
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
'------------------------------------ 2025/05/05 ------------------------------------
Public Class 五clsColorSet2401

    Implements IDisposable

#Region "使用方法について"
    ''**************************************************************************
    ''簡単なカラーパレットを作り、マウスイベントでカラー値を取得。
    ''--------------------------------------------------------------------------
    ''カラーの値はすべて、 Win32 COLOREF(Integer)。  64 Bit OS が前提条件　//　32 Bit OS では　Win32 COLOREF(Long)　に変更。
    ''--------------------------------------------------------------------------
    ''カラーの値の　NET System.Drawing.Color との変換。
    ''Color   = System.Drawing.ColorTranslator.fromwin32(ByRef Win32_COLOREF As Integer) 
    ''Integer = System.Drawing.ColorTranslator.towin32(ByRef Color構造体 As Color) 
    ''**************************************************************************
    ''宣言
    'Private WithEvents o色見本 As 五clsColorSet2401 = Nothing
    'Private flg_o色見本Loading As Boolean = True
    ''--------------------------------------------------------------------------
    ''作成　In FormLoad()
    'Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    '    '........
    '    o色見本 = New 五clsColorSet2401(flg_o色見本Loading, ByVal_rParent_As_Control, ByVal_rLeft_As_Integer, ByVal_rTop_As_Integer, ByVal_rWidth_As_Integer, ByVal_rHeight_As_Integer, _
    '                                Optional_ByVal_rEnabled_As_Boolean__True, Optional_ByVal_rMainPich234_As_Integer__3, Optional_ByVal_rGradationBoxSize_As_Integer__12, _
    '                                Optional_ByVal_rGradationPich_As_Integer__2, Optional_ByVal_rOutSideLineColor_As_Integer__&HFF0000&, Optional_ByVal_rOutSideLineWidth_As_Integer__15, _
    '                                Optional_ByVal_rFrameWidth_As_Integer__15, Optional_ByVal_rCurMainColor_As_Integer__&HC0C0C0&)
    '                                '● Me Location / Size in rParent == rLeft , rTop , rWidth , rHeight
    '    'あるいは ...
    '    o色見本 = New 五clsColorSet2401(flg_o色見本Loading, ByVal_rParent_As_Control, ByVal_rサイズ設定用ラベル_As_Label, _ 
    '                                Optional_ByVal_rEnabled_As_Boolean__True, Optional_ByVal_rMainPich234_As_Integer__3, Optional_ByVal_rGradationBoxSize_As_Integer__12, _
    '                                Optional_ByVal_rGradationPich_As_Integer__2, Optional_ByVal_rOutSideLineColor_As_Integer__&HFF0000&, Optional_ByVal_rOutSideLineWidth_As_Integer__15, _
    '                                Optional_ByVal_rFrameWidth_As_Integer__15, Optional_ByVal_rCurMainColor_As_Integer__&HC0C0C0&)
    '                                '● Me Location / Size in rParent == rサイズ設定用ラベル Location / Size
    '    'あるいは ...
    '    o色見本 = New 五clsColorSet2401(flg_o色見本Loading, ByVal_rParent_As_Control)  
    '                                '● Me Location / Size in rParent == 0, 0, 250, 250 ... All Propertys Set Default
    '    '........
    'End Sub
    ''-------------------------------------------------------------------------
    ''破棄　In FormClosing()
    'Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    '    o色見本.Dispose()
    'End Sub    
    ''**************************************************************************
    ''イベント群
    'Private Sub o色見本_OnColorChanged(ByVal rCurMainColor As Integer, ByVal rCurColor As Integer, ByVal rChangeMode As 五clsColorSet2401.ColorChangeMode, ByVal rEventMouseUp As Boolean) Handles o色見本.OnColorChanged
    '　　'マウス異動、あるいは外部からの設定による、中心部の箱型領域内のインジケーターの移動で発生しする。
    '　　'外側四方のグラデーション領域内での、●マウス異動でも発生する。
    '    If flg_o色見本Loading Then Exit Sub
    '    If rCurColor >= 0 Then
    '        Dim b as boolean = o色見本.CurColorSetIntoControlBackOrFore(LabelSample, RadioButton背景の色.Checked, True)
    '    End If
    '    'Debug.Print("色見本_OnColorChanged  " + CStr(rChangeMode) + "   " + CStr(rEventMouseUp))
    'End Sub
    ''--------------------------------------------------------------------------
    'Private Sub o色見本_OnMainColorChanged(ByVal rCurMainColor As Integer, ByVal rCurColor As Integer, ByVal rChangeMode As ColorChangeMode, ByVal rEventMouseUp As Boolean) Handles Me.OnMainColorChanged
    '　　'マウス異動、あるいは外部からの設定による、中心部の箱型領域内のインジケーターの移動で発生する。
    '　　'外側四方のグラデーション領域内での、●マウス異動では発生しない。
    '    If flg_o色見本Loading Then Exit Sub
    '    'Debug.Print("色見本_OnColorChanged  " + CStr(rChangeMode) + "   " + CStr(rEventMouseUp))
    'End Sub
    ''--------------------------------------------------------------------------
    'Private Sub o色見本_OnPanelChanged(ByVal rPropertyNames As String, ByVal rCurMainColor As Integer, ByVal rCurColor As Integer) Handles o色見本.OnPanelChanged
    '　　'カラーピッチが変更され、再描画された直後に発生する。
    '    If flg_o色見本Loading Then Exit Sub
    '    'Debug.Print("o色見本_OnPanelChanged")
    'End Sub
    ''**************************************************************************
#End Region

#Region "Private 変数および定数"
    Const cサイズ最小 As Integer = 100
    Const cサイズ最大 As Integer = 4000
    Private WithEvents mPCB As PictureBox = Nothing
    Private m描画呼び出し原因 As Integer = 0  '
    Private Const c原因再計算と中心部の描画は不要 As Integer = 124
    Private m原因クリック_5_6_ボタン_DN As Integer = 1000
    Private m原因クリック_5_6_ボタン_UP As Integer = 2000
    Private m選択枠の設定原因 As Boolean = False
    '-------------------------------------------------------------------------------
    Private mRects(8) As RECT, mRcGD上(64) As RECT, mRcGD右(64) As RECT, mRcGD下(64) As RECT, mRcGD左(64) As RECT
    'mRects(0) '中心のメインカラーパレット
    'mRects(1) '上のグラデーションボックス       'mRects(2) '右のグラデーションボックス        'mRects(3) '下のグラデーションボックス   'mRects(4) '左のグラデーションボックス
    'mRects(5) '上左のボタン　パネルモード変更   'mRects(6) '上右のボタン  グラデーション変更   'mRects(7) '下右のサンプルボックス       'mRects(8) '下左のサンプルボックス
    '-------------------------------------------------------------------------------
    Private Const cLineColor As Integer = 16711422 'RGB(254, 254, 254)
    Private mChaneMode As Integer, mEventMouseUp As Boolean
    Private mImgWD As Integer = 0 : Private mImgHT As Integer = 0
    Private m枠 As my五clsWakuwaku = Nothing
    '-------------------------------------------------------------------------------
    Private disposed As Boolean = False
#End Region

#Region "発行するイベント"
    '-------------------------------------------------------------------------------
    'rEventMouseUp As Boolean    'マウスアップイベントの場合のみ True
    '-------------------------------------------------------------------------------
    Enum ColorChangeMode
        外部からの設定
        マウス移動あるいはキー入力
        パネルモード234チェンジ
        グラデーションチェンジ
    End Enum
    '-------------------------------------------------------------------------------
    Event OnMainColorChanged(ByVal rCurMainColor As Integer, ByVal rCurColor As Integer, ByVal rChangeMode As ColorChangeMode, ByVal rEventMouseUp As Boolean)
    Event OnColorChanged(ByVal rCurMainColor As Integer, ByVal rCurColor As Integer, ByVal rChangeMode As ColorChangeMode, ByVal rEventMouseUp As Boolean)
    Event OnPanelChanged(ByVal rPropertyNames As String, ByVal rCurMainColor As Integer, ByVal rCurColor As Integer)
#End Region

#Region "初期化とファイナル"
    Public Sub New(ByRef wflg_o色見本Loading As Boolean, ByVal rParent As Control)
        wflg_o色見本Loading = True
        gggbol = Make_1_Del_2(1, True, rParent, 0, 0, 250, 250)
        wflg_o色見本Loading = False
    End Sub
    Public Sub New(ByRef wflg_o色見本Loading As Boolean, ByVal rParent As Control, ByVal rサイズ設定用ラベル As Label, _
                                Optional ByVal rEnabled As Boolean = True, Optional ByVal rMainPich234 As Integer = 3, Optional ByVal rGradationBoxSize As Integer = 12, _
                                Optional ByVal rGradationPich As Integer = 2, Optional ByVal rOutSideLineColor As Integer = &HFF0000&, Optional ByVal rOutSideLineWidth As Integer = 15, _
                                Optional ByVal rFrameWidth As Integer = 15, Optional ByVal rCurMainColor As Integer = &HC0C0C0)
        If rサイズ設定用ラベル Is Nothing Then Return
        wflg_o色見本Loading = True
        With rサイズ設定用ラベル
            .Visible = False
            gggbol = Make_1_Del_2(1, True, rParent, .Left, .Top, .Width, .Height, rEnabled, rMainPich234, rGradationBoxSize, rGradationPich, rOutSideLineColor, rOutSideLineWidth, rFrameWidth, rCurMainColor)
        End With
        wflg_o色見本Loading = False
    End Sub
    Public Sub New(ByRef wflg_o色見本Loading As Boolean, ByVal rParent As Control, ByVal rLeft As Integer, ByVal rTop As Integer, ByVal rWidth As Integer, ByVal rHeight As Integer, _
                                    Optional ByVal rEnabled As Boolean = True, Optional ByVal rMainPich234 As Integer = 3, Optional ByVal rGradationBoxSize As Integer = 12, _
                                    Optional ByVal rGradationPich As Integer = 2, Optional ByVal rOutSideLineColor As Integer = &HFF0000&, Optional ByVal rOutSideLineWidth As Integer = 15, _
                                    Optional ByVal rFrameWidth As Integer = 15, Optional ByVal rCurMainColor As Integer = &HC0C0C0)
        wflg_o色見本Loading = True
        gggbol = Make_1_Del_2(1, True, rParent, rLeft, rTop, rWidth, rHeight, rEnabled, rMainPich234, rGradationBoxSize, rGradationPich, rOutSideLineColor, rOutSideLineWidth, rFrameWidth, rCurMainColor)
        wflg_o色見本Loading = False
    End Sub
    Public Overloads Sub Dispose() Implements IDisposable.Dispose
        If Me.disposed = True Then Return
        m枠.Dispose()
        mPCB.Dispose()
        Me.disposed = True
        GC.SuppressFinalize(Me)
    End Sub
    Protected Overrides Sub Finalize()
        Me.Dispose()
        MyBase.Finalize()
        qqqqq("五clsColorSet2401.Finalize()")
    End Sub
#End Region

#Region "Public 外部とのI/O関数"
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Public Function Make_1_Del_2(ByVal rMake1Del2 As Integer, ByRef w色見本mLoading As Boolean, ByVal rParent As Control, _
                                    ByVal rLeft As Integer, ByVal rTop As Integer, ByVal rWidth As Integer, ByVal rHeight As Integer, _
                                    Optional ByVal rEnabled As Boolean = True, Optional ByVal rMainPich234 As Integer = 3, Optional ByVal rGradationBoxSize As Integer = 12, _
                                    Optional ByVal rGradationPich As Integer = 2, Optional ByVal rOutSideLineColor As Integer = &HFF0000&, Optional ByVal rOutSideLineWidth As Integer = 15, _
                                    Optional ByVal rFrameWidth As Integer = 15, Optional ByVal rCurMainColor As Integer = &HC0C0C0) As Boolean
        '----------------------------------------------------------------------------------------------------------------------------------
        'この関数で、Color構造体　の引数を指定する場合は、'Integer = System.Drawing.ColorTranslator.towin32( nColor構造体 ) で変換して指定する。
        'rOutSideLineColor As Integer / rCurMainColor As Integer
        '----------------------------------------------------------------------------------------------------------------------------------
        'Debug.Print("Start in Make_1_Del_2()")
        Dim RET As Boolean = False
        w色見本mLoading = True
        Try
            Select Case rMake1Del2
                Case 1
                    If mPCB Is Nothing Then
                        Enabled = rEnabled                              'カラーボックス全体の Enabled　 False では淡色の表示になる。
                        MainPich234 = rMainPich234                      'カラーボックス全体のセルの縦横の数　　2 ～ 4　全セル数は、 (MainPich234 * MainPich234) の３乗 になる。
                        GradationBoxSize = rGradationBoxSize            'グラデーションボックス幅の、カラーボックス全体のサイズに対する、パーセント比率
                        GradationPich = rGradationPich                  'グラデーションの変化の強弱   1 ～ 3
                        OutSideLineColor = rOutSideLineColor            'このコントロールの外枠の色。 ( Win32 COLOREF値 Integer )
                        OutSideLineWidth = rOutSideLineWidth            'カラーボックス全体を囲むフォーカス表示枠の太さ。  全体の縦横サイズの小さい値の、1/1000 単位の値。 5 ～ 100
                        FrameWidth = rFrameWidth                        'カラー領域の外縁の白い枠の幅。                   全体の縦横サイズの小さい値の、1/1000 単位の値。 5 ～ 100
                        CurMainColor = rCurMainColor                    '最初に表示されるときに選択するカラーの値 ( Win32 COLOREF値 Integer )
                        RET = Make_Del(1, rParent, rLeft, rTop, rWidth, rHeight)
                    Else
                        RET = True
                    End If
                Case Else
                    If mPCB IsNot Nothing Then
                        RET = Make_Del(2, Nothing, 0, 0, 0, 0)
                    Else
                        RET = True
                    End If
            End Select
        Catch ex As Exception
            MsgBox("ERROR in Make_1_Del_2()" & gggCR2 & ex.ToString)
            RET = False
        End Try
        w色見本mLoading = False
        Return RET
    End Function
    Public Sub Refresh()
        If mPCB Is Nothing Then Return
        mPCB.Refresh()
    End Sub
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Public Function Make_Del(ByVal Make1_Del2 As Integer, ByVal rParent As Control, _
                             ByVal rLeft As Integer, ByVal rTop As Integer, ByVal rWidth As Integer, ByVal rHeight As Integer) As Boolean
        'ユーザーホームの　Form_Load　Form_close イベントで呼び出す。
        Try
            Select Case Make1_Del2
                Case 1
                    If rParent Is Nothing Then Return False
                    mPCB = New PictureBox
                    If mPCB Is Nothing Then Return False
                    '--------------------------------------------------
                    'この後で描画が始まり　m枠　が必要になる
                    m枠 = New my五clsWakuwaku
                    gggbol = m枠.aa_Make(mPCB, 1, Color.Red)
                    gggbol = m枠.aa_BringToFront()
                    '--------------------------------------------------
                    With mPCB
                        .Parent = rParent
                        .BorderStyle = Windows.Forms.BorderStyle.None
                        .SizeMode = PictureBoxSizeMode.Normal
                    End With
                    If Not zzSetSizeDraw(1, rLeft, rTop, rWidth, rHeight) Then
                        m枠.Dispose() : m枠 = Nothing
                        mPCB.Dispose() : mPCB = Nothing
                        Return False
                    End If
                    Return (mPCB IsNot Nothing)
                Case Else
                    If m枠 IsNot Nothing Then
                        m枠.Dispose() : m枠 = Nothing
                    End If
                    If mPCB IsNot Nothing Then
                        mPCB.Dispose() : mPCB = Nothing
                    End If
                    Return True
            End Select
        Catch ex As Exception
            MsgBox("ERROR in Make_Del()")
            Return False
        End Try
    End Function
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Public Function ReSizeDraw(ByVal rRightSpace As Integer, ByVal rBottomSpace As Integer) As Boolean
        With mPCB
            Return zzSetSizeDraw(2, .Left, .Top, .Parent.ClientRectangle.Width - .Left - rRightSpace, .Parent.ClientRectangle.Height - .Top - rBottomSpace)
        End With
    End Function
    Public Function ReSizeDraw(ByVal rLeft As Integer, ByVal rTop As Integer, ByVal rWidth As Integer, ByVal rHeight As Integer) As Boolean
        Return zzSetSizeDraw(2, rLeft, rTop, rWidth, rHeight)
    End Function
    Private Function zzSetSizeDraw(ByVal Make1_ReSize2_Draw3 As Integer, ByVal rLeft As Integer, ByVal rTop As Integer, ByVal rWidth As Integer, ByVal rHeight As Integer) As Boolean
        Static CallCount As Integer
        Static ここから呼び出し中 As Boolean
        If mPCB Is Nothing Then Return False
        If ここから呼び出し中 Then Return False
        '-------------------------------------------------------
        Select Case Make1_ReSize2_Draw3
            Case 1, 2
                'Size Chang or New Make
                Dim w As Integer = Ⅹ数値範囲Int(cサイズ最小, cサイズ最大, rWidth)
                Dim h As Integer = Ⅹ数値範囲Int(cサイズ最小, cサイズ最大, rHeight)
                w = (w \ 2) * 2
                h = (h \ 2) * 2
                If mPCB.Width <> w Or mPCB.Height <> h Then mPCB.SetBounds(Math.Max(0, rLeft), Math.Max(0, rTop), w, h)
                Dim DoMakeNewImg As Boolean = False
                If mPCB.Image Is Nothing Then DoMakeNewImg = True Else DoMakeNewImg = (mPCB.Image.Width <> w Or mPCB.Image.Height <> h)
                If DoMakeNewImg Then
                    If mPCB.Image IsNot Nothing Then
                        mPCB.Image.Dispose() : mPCB.Image = Nothing
                    End If
                    mPCB.Image = New Bitmap(w, h)
                    m選択枠の設定原因 = False
                    CallCount += 1
                    'qqqqq(CStr(CallCount) & " ** in SetSizeDraw() -- Make New Image")
                End If
            Case 3
                'no op
        End Select
        If mPCB.Image Is Nothing Then Return False
        '-------------------------------------------------------
        If True Then
            ここから呼び出し中 = True
            mPCB.SetBounds(0, 0, mPCB.Image.Width, mPCB.Image.Height, BoundsSpecified.Size)
            '2023/12/22 全体サイズが小さくなった場合に、サイズ依存のプロパを修正する。
            GradationBoxSize = GradationBoxSize
            FrameWidth = FrameWidth
            OutSideLineWidth = OutSideLineWidth
            ここから呼び出し中 = False
        End If
        '-------------------------------------------------------
        Dim RET As Boolean = False
        Dim grh As Graphics = Graphics.FromImage(mPCB.Image)
        If grh IsNot Nothing Then
            Dim hdc As IntPtr = grh.GetHdc()
            If hdc <> 0 Then
                If m選択枠の設定原因 = True Then
                    '描画は不要　選択枠　の移動に伴う　mPCB　の描画イベントで、mPCB.Image　には無関係で、そのままでよい。
                    m選択枠の設定原因 = False
                    RET = True
                Else
                    RET = zzDrawMain(hdc)
                End If
                grh.ReleaseHdc(hdc)
                mPCB.Refresh()
            End If
        End If
        Return RET
    End Function
    Public Function GetSize(ByRef wWidth As Integer, ByRef wHeight As Integer) As Boolean
        If mPCB Is Nothing Then Return False
        With mPCB
            If .Image Is Nothing Then Return False
            With .Image
                wWidth = .Width
                wHeight = .Height
                Return True
            End With
        End With
    End Function
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Public Function 色1色2は現在モードでの誤差範囲内で同じ(ByVal 色1 As Color, ByVal 色2 As Color) As Boolean
        Dim c1 As Integer = System.Drawing.ColorTranslator.ToWin32(色1)
        Dim c2 As Integer = System.Drawing.ColorTranslator.ToWin32(色2)
        Return 色1色2は現在モードでの誤差範囲内で同じ(c1, c2)
    End Function
    Public Function 色1色2は現在モードでの誤差範囲内で同じ(ByVal 色1 As Integer, ByVal 色2 As Integer) As Boolean
        '色1 / 色2 = Win32 COLOREF値
        Dim gg2, bb1, rr1, chk, gg1, rr2, bb2 As Integer
        Dim RET As Boolean = False
        chk = CInt(256 / (MainPich234 * MainPich234) / 2)
        gggint = Ⅹ色RGB値(色1, rr1, gg1, bb1)
        gggint = Ⅹ色RGB値(色2, rr2, gg2, bb2)
        RET = (System.Math.Abs(rr1 - rr2) <= chk) And (System.Math.Abs(gg1 - gg2) <= chk) And (System.Math.Abs(bb1 - bb2) <= chk)
        'If e And ((rr1 <> rr2) Or (gg1 <> gg2) Or (bb1 <> bb2)) Then
        '    qqqqq CStr(e) + " / chk=" + CStr(chk) + " / " + CStr(rr1) + "," + CStr(gg1) + "," + CStr(bb1) + " | " + CStr(rr2) + "," + CStr(gg2) + "," + CStr(bb2)
        'End If
        Return RET
    End Function
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Public Function Color_to_INT(ByVal Color構造体 As Color) As Integer
        Return System.Drawing.ColorTranslator.ToWin32(Color構造体)
    End Function
    Public Function Color_from_INT(ByVal IntVal色 As Integer) As Color
        Return System.Drawing.ColorTranslator.FromWin32(IntVal色)
    End Function
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Public Function ColorIntValHexStr(ByVal ColorINT As Integer) As String
        Return "&H" & Microsoft.VisualBasic.Right("00000000" & Hex(ColorINT), 8) & "&"
    End Function
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Public Function CurColorAndTextSetIntoControl(ByRef wCont As Control, ByVal rSetTextColorIntVal As Boolean, ByVal rDoControlRefresh As Boolean) As Boolean
        Try
            With wCont
                Dim c As Integer = CurColor
                .BackColor = Color_from_INT(c)
                If rSetTextColorIntVal Then
                    .ForeColor = HitBoxLineColorNow
                    .Text = ColorIntValHexStr(c)
                End If
                If rDoControlRefresh Then .Refresh()
            End With
            Return True
        Catch ex As Exception
            MsgBox("ERROR in ucColorBox.CurColorAndTextSetIntoControl() " & vbCrLf & vbCrLf & ex.ToString)
            Return False
        End Try
    End Function
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Public Function CurColorSetIntoControlBackOrFore(ByRef wCont As Control, ByVal rSet_BackTrue_ForeFalse As Boolean, ByVal rDoControlRefresh As Boolean) As Boolean
        Try
            With wCont
                Dim ccc As Color = Color_from_INT(CurColor)
                If rSet_BackTrue_ForeFalse Then
                    .BackColor = ccc
                Else
                    .ForeColor = ccc
                End If
                If rDoControlRefresh Then .Refresh()
            End With
            Return True
        Catch ex As Exception
            MsgBox("ERROR in ucColorBox.CurColorSetIntoControlBackOrFore() " & vbCrLf & vbCrLf & ex.ToString)
            Return False
        End Try
    End Function
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
#End Region

#Region "Private 関数 mPCB MouseEvents()"
    Private Sub mPCB_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles mPCB.MouseDown
        Dim int As Integer = MouseEvent(1, e.X, e.Y, 0)
    End Sub
    Private Sub mPCB_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles mPCB.MouseMove
        Dim int As Integer = MouseEvent(2, e.X, e.Y, 0)
        mPCB.Refresh()
    End Sub
    Private Sub mPCB_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles mPCB.MouseUp
        Dim int As Integer = MouseEvent(3, e.X, e.Y, 0)
        mPCB.Refresh()
    End Sub
    Private Function MouseEvent(ByVal rDown1_Move2_Up3 As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal ErrorRetColor As Integer) As Integer
        Static mマウスは押されている As Boolean : Static mマウスダウンX, mマウスダウンY As Integer
        Static mクリック_5_6_ボタン As Integer
        Dim ccc, a As Integer : Dim MainPich234_Change, GradationPich_Change As Boolean : Dim wdgY, wdgX As Integer
        mEventMouseUp = False
        '*************************************************
        If rDown1_Move2_Up3 = 3257 Then 'MouseDowningCheck
            Return IIf(mマウスは押されている, 2976, 0)
        End If
        If Not Me.Enabled Then
            mマウスは押されている = False : Return ErrorRetColor
        End If
        If mPCB Is Nothing Then
            Return ErrorRetColor
        End If
        '*************************************************
        'マウスダウン
        If rDown1_Move2_Up3 = 1 Then
            mマウスは押されている = True : mマウスダウンX = X : mマウスダウンY = Y : mクリック_5_6_ボタン = 0
            For a = 5 To 6
                If ⅩRect内にXY座標がある(X, Y, mRects(a)) Then
                    'ボタン押し下げ　描画
                    mクリック_5_6_ボタン = a
                    '--------------------------
                    gggbol = zzBtnDrawInImageすぐに(False, mクリック_5_6_ボタン)
                    '--------------------------
                    Return a
                    '--------------------------
                End If
            Next
        End If
        '*************************************************
        'マウスダウン(ボタン以外)　と　マウスムーブ
        If mマウスは押されている Then
            'マウスの位置の色をえる
            mEventMouseUp = False
            If mクリック_5_6_ボタン > 0 Then
                '何もしない
            Else
                ccc = -1
                Dim bm As Bitmap = mPCB.Image
                If X < 0 Or Y < 0 Or X > bm.Width - 1 Or Y > bm.Height - 1 Then
                    qqqqq("ERROR in 五clsColorSet2401.MouseEvent()" & vbCrLf & "bm.GetPixel(X, Y) " & CStr(X) & ", " & CStr(Y) & vbCrLf & "bm.size(Width, Height) " & CStr(bm.Width) & ", " & CStr(bm.Height))
                Else
                    Dim c As Color = bm.GetPixel(X, Y)
                    ccc = Color_to_INT(c)
                    If ccc <> cLineColor And ccc >= 0 Then
                        ccc = MouseEvent_SUB(rDown1_Move2_Up3, X, Y, ccc)
                        If rDown1_Move2_Up3 <> 3 Then
                            Return ccc
                        End If
                    End If
                End If
            End If
        End If
        '*************************************************
        'マウスアップ
        If rDown1_Move2_Up3 = 3 Then
            'm選択枠の設定原因 = False
            If mマウスは押されている Then
                mEventMouseUp = True
                MainPich234_Change = False
                GradationPich_Change = False
                If System.Math.Abs(mマウスダウンX - X) < 3 And System.Math.Abs(mマウスダウンY - Y) < 3 Then
                    If ⅩRect内にXY座標がある(X, Y, mRects(5)) Then       '上左のボタン　パネルモード変更　　MainPich234()
                        'Debug.Print Hex(CurMainColor)
                        a = MainPich234 + 1
                        If a > 4 Then MainPich234() = 2 Else MainPich234() = a 'ここで　 mPCB.Refresh()　が実行される
                        MainPich234_Change = True
                        'Debug.Print Hex(CurMainColor): ccc = pcb.Point(shp.left + 1, shp.Top + 1): Debug.Print "*" + Hex(ccc)
                    ElseIf ⅩRect内にXY座標がある(X, Y, mRects(6)) Then   '上右のボタン  グラデーション変更
                        a = GradationPich + 1
                        'Debug.Print Hex(CurMainColor):  Debug.Print "*" + Hex(CurColor)
                        GradationPich_Change = True
                        mChaneMode = 3
                        If a > 3 Then GradationPich() = 1 Else GradationPich() = a
                        mChaneMode = 0
                        'Debug.Print Hex(CurMainColor):  Debug.Print "*" + Hex(CurColor)
                    End If

                ElseIf mクリック_5_6_ボタン = 5 Or mクリック_5_6_ボタン = 6 Then
                    gggbol = zzBtnDrawInImageすぐに(True, mクリック_5_6_ボタン)
                End If

                If ⅩRect内にXY座標がある(X, Y, mRects(0)) Then
                    ccc = zzColorValGetSetXY(1, 0, X, Y, wdgX, wdgY)
                    If ccc <> cLineColor And ccc >= 0 Then
                        gggint = MouseEvent_SUB(rDown1_Move2_Up3, X, Y, ccc)
                    End If
                End If
                mEventMouseUp = False
                mChaneMode = 0
                '-----------------------------------------------------------------------
            End If
            mマウスは押されている = False : mマウスダウンX = X : mマウスダウンY = Y : mクリック_5_6_ボタン = 0
        End If
        '*************************************************
        'If rDown1_Move2_Up3 <> 2 Then
        'Debug.Print "MouseEvent  " + CStr(rDown1_Move2_Up3)
        'End If
        'If mマウスは押されている Then
        'mmm = mmm + 1: If mmm Mod 10 = 0 Then Debug.Print Hex(CurMainColor) + ",  " + Hex(CurColor)
        'End If
    End Function
    Private Function MouseEvent_SUB(ByVal rDown1_Move2_Up3 As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal ccc As Integer) As Integer
        Dim OnlySmpDraw, GradBoxDraw As Boolean
        Dim wdgY, wdgX, cccnew As Integer
        If ccc <> cLineColor And ccc >= 0 Then
            cccnew = ccc
            GradBoxDraw = ⅩRect内にXY座標がある(X, Y, mRects(0))
            OnlySmpDraw = ⅩRect内にXY座標がある(X, Y, mRects(1)) Or ⅩRect内にXY座標がある(X, Y, mRects(2)) Or ⅩRect内にXY座標がある(X, Y, mRects(3)) Or ⅩRect内にXY座標がある(X, Y, mRects(4))
            If GradBoxDraw Or OnlySmpDraw Then
                If rDown1_Move2_Up3 = 3 Then
                    mEventMouseUp = True
                End If
                If GradBoxDraw Then
                    m描画呼び出し原因 = c原因再計算と中心部の描画は不要
                    cccnew = zzColorValGetSetXY(1, ccc, X, Y, wdgX, wdgY)
                    mChaneMode = 1
                    'カラーパレットの状態により、指定された色がデジタイズされて返される。
                    CurMainColor = zzColorValGetSetXY(2, cccnew, 0, 0, wdgX, wdgY)
                    mChaneMode = 0
                ElseIf OnlySmpDraw Then
                    cccnew = ccc
                    mChaneMode = 1
                    CurColor = ccc
                    mChaneMode = 0
                End If
                m描画呼び出し原因 = 0
            End If
            Return cccnew
        End If
    End Function
#End Region

#Region "Public プロパティ"
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private mOutSideLineWidth As Integer = 15
    Public Property OutSideLineWidth() As Integer
        'カラーボックス全体を囲む表示枠の太さ。全体の縦横サイズの小さいほうの値の、1/1000 単位の値。
        Get
            Return mOutSideLineWidth
        End Get
        Set(ByVal Value As Integer)
            If mPCB Is Nothing Then Return
            Dim old As Integer = mOutSideLineWidth
            Dim xy As Integer = Math.Min(100, Math.Max(5, Math.Min(mPCB.Width, mPCB.Height) \ 10))
            mOutSideLineWidth = Ⅹ数値範囲Int(5, xy, Value)
            If (old <> mOutSideLineWidth) Then gggbol = zzmPCB_WndAllRefresh()
        End Set
    End Property
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private mOutSideLineColor As Integer = &HFF0000&
    Public Property OutSideLineColor() As Integer
        'カラーボックス全体を囲む表示枠の色。
        Get
            Return mOutSideLineColor
        End Get
        Set(ByVal Value As Integer)
            mOutSideLineColor = Ⅹ色の値の検査修正値(Value) : gggbol = zzmPCB_WndAllRefresh()
        End Set
    End Property
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private mGradationBoxSize As Integer = 12
    Public Property GradationBoxSize() As Integer
        'グラデーションボックス幅の、セル群全体部分の幅に対する、パーセント比率
        Get
            Return mGradationBoxSize
        End Get
        Set(ByVal Value As Integer)
            If mPCB Is Nothing Then Return
            Dim old As Integer = mGradationBoxSize
            Dim xy As Integer = Math.Min(mPCB.Width, mPCB.Height) \ 5
            mGradationBoxSize = Ⅹ数値範囲Int(8, Math.Min(xy, 30), Value)
            If (old <> mGradationBoxSize) Then gggbol = zzmPCB_WndAllRefresh()
        End Set
    End Property
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private mGradationPich As Integer = 2
    Public Property GradationPich() As Integer
        'グラデーションの強弱   1 to 3
        Get
            Return mGradationPich
        End Get
        Set(ByVal Value As Integer)
            mGradationPich = Ⅹ数値範囲Int(1, 3, Value)
            CurMainColor = CurMainColor
        End Set
    End Property
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private mEnabled As Boolean = True
    Public Property Enabled() As Boolean
        'カラーボックス全体の Enabled　 False では淡色の表示になる。
        Get
            Return mEnabled
        End Get
        Set(ByVal Value As Boolean)
            mEnabled = Value : gggbol = zzmPCB_WndAllRefresh()
        End Set
    End Property
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private mMainPich234 As Integer = 3
    Public Property MainPich234() As Integer
        'MainPich234　カラーボックス全体のセルの縦横の数　2～4　全セル数は、 (MainPich234 * MainPich234) * (MainPich234 * MainPich234) * (MainPich234 * MainPich234) になる。
        '2*2*2 / 3*3*3 / 4*4*4  一般化したカラーセルの描画とデーター取得　　5*5*5　ではセルのデジタル値が大きくずれるので使用できない。
        Get
            Return mMainPich234
        End Get
        Set(ByVal Value As Integer)
            mMainPich234 = Ⅹ数値範囲Int(2, 4, Value) : gggbol = zzmPCB_WndAllRefresh()
        End Set
    End Property
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private mFrameWidth As Integer = 15
    Public Property FrameWidth() As Integer
        'カラーボックス全体を囲むフレームのピクセル幅。全体の縦横サイズの小さいほうの値の、1/1000 単位の値。 
        Get
            Return mFrameWidth
        End Get
        Set(ByVal Value As Integer)
            If mPCB Is Nothing Then Return
            Dim old As Integer = mFrameWidth
            Dim xy As Integer = Math.Min(100, Math.Max(5, Math.Min(mPCB.Width, mPCB.Height) \ 10))
            mFrameWidth = Ⅹ数値範囲Int(5, xy, Value)
            If (old <> mFrameWidth) Then gggbol = zzmPCB_WndAllRefresh()
        End Set
    End Property
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private mCellPichX As Integer = 2
    Private Property CellPichX() As Integer
        '１セルのピクセル幅　　
        Get
            Return mCellPichX
        End Get
        Set(ByVal Value As Integer)
            '描画コード内で設定される。ここから描画を呼び出すと無限ループになる
            mCellPichX = Ⅹ数値範囲Int(1, cサイズ最大 / (MainPich234 * MainPich234 * MainPich234), Value)
        End Set
    End Property
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private mCellPichY As Integer = 2
    Private Property CellPichY() As Integer
        '１セルピクセル高さ
        Get
            Return mCellPichY
        End Get
        Set(ByVal Value As Integer)
            '描画コード内で設定される。ここから描画を呼び出すと無限ループになる
            mCellPichY = Ⅹ数値範囲Int(1, cサイズ最大 / (MainPich234 * MainPich234 * MainPich234), Value)
        End Set
    End Property
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private mCurMainColor As Integer = &HC0C0C0
    Public Property CurMainColor() As Integer
        '現在のカラー  カラーセルの中の選択ボックスのある位置の色
        Get
            Return mCurMainColor
        End Get
        '**********************************************************
        Set(ByVal Value As Integer)
            Dim c As Integer
            If Value < 0 Then c = Ⅹ色LONG値(Value) Else c = Ⅹ色の値の検査修正値(Value) 'システムカラーは負の値
            If c = cLineColor Then c = &HFFFFFF&
            If c >= 0 Then
                Dim OldColor As Integer = mCurMainColor
                mCurMainColor = c
                '------------------------------------------------------------
                If mPCB IsNot Nothing Then
                    m描画呼び出し原因 = c原因再計算と中心部の描画は不要
                    gggbol = zzグラデ領域描画すぐに(0, True)
                    If OldColor <> mCurMainColor Or mEventMouseUp Then '2022/04/10 change
                        RaiseEvent OnMainColorChanged(mCurMainColor, mCurMainColor, mChaneMode, mEventMouseUp)
                    End If
                End If
                '------------------------------------------------------------
                CurColor = mCurMainColor
                '------------------------------------------------------------
            End If
            'Debug.Print "Let CurMainColor() out"
        End Set
    End Property
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private mCurColor As Integer = &HC0C0C0
    Public Property CurColor() As Integer
        '現在のカラー  グラデーションボックスで選択された色。あるいは、グラデーションボックスでの選択以前の CurMainColor
        Get
            Return mCurColor
        End Get
        '**********************************************************
        Set(ByVal Value As Integer)
            Static ここから呼び出し As Boolean
            If ここから呼び出し Then Return
            Dim c As Integer
            If Value < 0 Then c = Ⅹ色LONG値(Value) Else c = Ⅹ色の値の検査修正値(Value) 'システムカラーは負の値
            If c = cLineColor Then c = &HFFFFFF&
            If c >= 0 Then
                Dim OldColor As Integer = mCurColor
                mCurColor = c
                '------------------------------------------------------------
                If mPCB IsNot Nothing Then
                    m描画呼び出し原因 = c原因再計算と中心部の描画は不要
                    gggbol = zzグラデ領域描画すぐに(0, True)
                    m選択枠の設定原因 = False
                    If OldColor <> mCurColor Or mEventMouseUp Then
                        If mChaneMode = 0 Then
                            ここから呼び出し = True
                            CurMainColor = mCurColor
                            mCurColor = mCurMainColor
                            ここから呼び出し = False
                        End If
                        RaiseEvent OnColorChanged(mCurMainColor, mCurColor, mChaneMode, mEventMouseUp)
                        'Debug.Print(ColorIntValHexStr(mCurColor) & ",,," & ColorIntValHexStr(Color_to_INT(HitBoxLineColorNow)))
                    End If
                End If
                '------------------------------------------------------------
                'Debug.Print "Let CurColor() out"
                'Debug.Print "mChaneMode = "
            End If
        End Set
    End Property
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Public ReadOnly Property HitBoxLineColorNow() As Color
        Get
            Return m枠.CurColor
        End Get
    End Property
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
#End Region

#Region "Private 描画関数"
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private Function zzmPCB_WndAllRefresh() As Boolean
        Try
            If mPCB Is Nothing Then Return False
            If mPCB.Image Is Nothing Then Return False
            m選択枠の設定原因 = False
            Return zzSetSizeDraw(3, 0, 0, 0, 0)
        Catch ex As Exception
            qqqqq("ERROR in zzmPCB_WndAllRefresh()")
            Return False
        End Try
    End Function
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private Function zzDrawMain(ByVal hDC As Integer) As Boolean
        '-------------------------------------------------------------------------------
        Static old_Enabled As Boolean
        Static old_GradationBoxSize As Integer : Static old_GradationPich As Integer
        Static old_MainPich234 As Integer : Static old_FrameWidth As Integer
        Static old_CellPichX As Integer : Static old_CellPichY As Integer
        '2023/08/02 new ----------------------------------------------------------------
        Static cColors(10000) As Integer : Const 色をぼかすSHIFT As Integer = 5000, Basepich2 As Integer = 0, Basepich3 As Integer = 100, Basepich4 As Integer = 900
        '2023/08/02 new ----------------------------------------------------------------
        '*******************************************************************************
        'gggbol = qqqqq("zzDrawMain() IN")
        '*******************************************************************************
        If mPCB Is Nothing Then Return False
        If hDC = 0 Then Return False
        'If False = Form1.最初の描画は実行された Then Return False
        '*******************************************************************************
        If mImgWD = mPCB.Image.Width Or mImgHT = mPCB.Image.Height Then
            m描画呼び出し原因 = 0
        End If
        mImgWD = mPCB.Image.Width
        mImgHT = mPCB.Image.Height
        Dim フォーカスライン幅 As Integer = Math.Max(2, Math.Min(mImgWD, mImgHT) * OutSideLineWidth \ 1000)
        Dim フレーム幅 As Integer = Math.Max(2, Math.Min(mImgWD, mImgHT) * FrameWidth \ 1000)
        Dim 色をぼかす As Boolean = (Not Me.Enabled)
        '*******************************************************************************
        Try
            '*******************************************************************************
            If m描画呼び出し原因 >= m原因クリック_5_6_ボタン_UP Then GoTo Goto_m原因クリック_5_6_ボタン_UP
            If m描画呼び出し原因 >= m原因クリック_5_6_ボタン_DN Then GoTo Goto_c原因クリック_5_6_ボタン_DN
            If m描画呼び出し原因 = c原因再計算と中心部の描画は不要 Then GoTo Goto_c原因再計算と中心部の描画は不要
            '*******************************************************************************
            If m描画呼び出し原因 = 0 Then
                '-------------------------------------------------------------------------------
                Dim cellxy As Integer = MainPich234 * MainPich234 * MainPich234
                '-------------------------------------------------------------------------------
                Dim x As Integer = mImgWD - フォーカスライン幅 - フォーカスライン幅 - フレーム幅 - フレーム幅 '''''' - 1
                Dim y As Integer = mImgHT - フォーカスライン幅 - フォーカスライン幅 - フレーム幅 - フレーム幅 ''''''- 1
                Dim PichX As Integer = Int(x / (1 + 2 * (GradationBoxSize / 100)) / cellxy)
                Dim PichY As Integer = Int(y / (1 + 2 * (GradationBoxSize / 100)) / cellxy)
                CellPichX = PichX
                CellPichY = PichY
                Dim mainWD As Integer = cellxy * PichX
                Dim mainHT As Integer = cellxy * PichY
                Dim gradWD As Integer = Ⅹ数値範囲Int(8, 1000, (x - mainWD) / 2)
                Dim gradHT As Integer = Ⅹ数値範囲Int(8, 1000, (y - mainHT) / 2)
                '-------------------------------------------------------------------------------
                Dim xxx0, xxx1, xxx2, xxx3, xxx4, xxx5, yyy0, yyy1, yyy2, yyy3, yyy4, yyy5 As Integer
                Dim 幅幅 As Integer = フォーカスライン幅 + フレーム幅
                xxx0 = 0 : xxx1 = 幅幅 : xxx2 = xxx1 + gradWD : xxx3 = xxx2 + mainWD : xxx4 = mImgWD - 幅幅 : xxx5 = xxx4 + 幅幅
                yyy0 = 0 : yyy1 = 幅幅 : yyy2 = yyy1 + gradHT : yyy3 = yyy2 + mainHT : yyy4 = mImgHT - 幅幅 : yyy5 = yyy4 + 幅幅
                '*******************************************************************************
                'qqqqq(CStr(mImgWD)) : qqqqq(CStr(mImgWD))
                '*******************************************************************************
                gggint = SetRect(mRects(0), xxx2, yyy2, xxx3, yyy3) '中心のメインカラーパレット
                '-------------------------------------------------------------------------------
                gggint = SetRect(mRects(5), xxx1, yyy1, xxx2 - 1, yyy2 - 1) '上左のサンプルボックス  ボタンに使用
                gggint = SetRect(mRects(6), xxx3 + 1, yyy1, xxx4, yyy2 - 1) '上右のサンプルボックス  ボタンに使用
                gggint = SetRect(mRects(7), xxx3 + 1, yyy3 + 1, xxx4, yyy4) '下右のサンプルボックス
                gggint = SetRect(mRects(8), xxx1, yyy3 + 1, xxx2 - 1, yyy4) '下左のサンプルボックス
                '-------------------------------------------------------------------------------
                gggint = SetRect(mRects(1), xxx2, yyy1, xxx3, yyy2) '上のグラデーションボックス
                gggint = SetRect(mRects(2), xxx3, yyy2, xxx4, yyy3) '右のグラデーションボックス
                gggint = SetRect(mRects(3), xxx2, yyy3, xxx3, yyy4) '下のグラデーションボックス
                gggint = SetRect(mRects(4), xxx1, yyy2, xxx2, yyy3) '左のグラデーションボックス
                '-------------------------------------------------------------------------------
                Dim eee, delsize As Integer
                For eee = 1 To cellxy
                    delsize = IIf(eee = cellxy, 1, 0)
                    With mRcGD上(eee) : .lll = xxx2 + (eee - 1) * PichX : .ttt = yyy1 : .rrr = .lll + PichX - delsize : .bbb = yyy2 - 1 : End With
                    With mRcGD右(eee) : .lll = xxx3 + 1 : .ttt = yyy2 + (eee - 1) * PichY : .rrr = xxx4 : .bbb = .ttt + PichY - delsize : End With
                    With mRcGD下(eee) : .lll = xxx2 + (eee - 1) * PichX : .ttt = yyy3 + 1 : .rrr = .lll + PichX - delsize : .bbb = yyy4 : End With
                    With mRcGD左(eee) : .lll = xxx1 : .ttt = yyy2 + (eee - 1) * PichY : .rrr = xxx2 - 1 : .bbb = .ttt + PichY - delsize : End With
                Next
                '-------------------------------------------------------------------------------
                mRcGD上(cellxy).rrr = mRcGD上(cellxy).rrr + 1
                mRcGD右(cellxy).bbb = mRcGD右(cellxy).bbb + 1
                mRcGD下(cellxy).rrr = mRcGD下(cellxy).rrr + 1
                mRcGD左(cellxy).bbb = mRcGD左(cellxy).bbb + 1
                '*******************************************************************************
                Dim BoxNum As Integer = MainPich234 * MainPich234
                Dim ColorStep As Short = CShort(255 / (BoxNum - 1))
                Dim dxnn As Integer = PichX * BoxNum
                Dim dxww As Integer = PichX
                Dim dynn As Integer = PichY * BoxNum
                Dim dyhh As Integer = PichY
                Dim mmm As Integer = BoxNum - 1
                Dim brs, old As Integer
                Dim CRR, CBB, CGG, ccc As Integer
                Dim a, b, c, aa1, aax, aay, adx, ady, x1, x2, y1, y2 As Integer
                Dim rc As RECT
                '-------------------------------------------------------------------------------
                gggbol = ⅩRectDraw(hDC, rc, cLineColor, 0, 0, mImgWD, mImgHT, False) 'Clera Old Colors
                '-------------------------------------------------------------------------------
                '2023/08/02 new ----------------------------------------------------------------
                Dim MakeNewColorData As Boolean = False
                Dim idx As Integer = 0
                b = IIf(色をぼかす, 色をぼかすSHIFT, 0)
                Select Case MainPich234
                    Case 2 : idx = b + Basepich2
                    Case 3 : idx = b + Basepich3
                    Case 4 : idx = b + Basepich4
                End Select
                If (MainPich234 = 2 And cColors(b + Basepich2 + 1) > 0) Or (MainPich234 = 3 And cColors(b + Basepich3 + 1) > 0) Or (MainPich234 = 4 And cColors(b + Basepich4 + 1) > 0) Then
                    MakeNewColorData = False
                    'qqqqq("zzDrawMain() ** ary data use")
                Else
                    MakeNewColorData = True
                    'qqqqq("zzDrawMain() --------ary data make")
                End If
                '2023/08/02 new ----------------------------------------------------------------
                For a = 0 To mmm
                    If MakeNewColorData Then
                        CRR = a * ColorStep
                        If CRR > 255 Then CRR = 255
                        If CRR < 0 Then CRR = 0
                        If 色をぼかす Then CRR = CRR + (255 - CRR) \ 2
                    End If
                    aa1 = a \ MainPich234
                    aax = dxnn * (a - (aa1 * MainPich234))
                    aay = dynn * aa1
                    For b = 0 To mmm
                        If MakeNewColorData Then
                            CGG = b * ColorStep
                            If CGG > 255 Then CGG = 255
                            If CGG < 0 Then CGG = 0
                            If 色をぼかす Then CGG = CGG + (255 - CGG) \ 2
                        End If
                        x1 = xxx2 + aax + (b * PichX)
                        x2 = x1 + dxww
                        If b <> mmm Then adx = 1 Else adx = 0
                        For c = 0 To mmm
                            If MakeNewColorData Then
                                CBB = c * ColorStep
                                If CBB > 255 Then CBB = 255
                                If CBB < 0 Then CBB = 0
                                If 色をぼかす Then CBB = CBB + (255 - CBB) \ 2
                            End If
                            y1 = yyy2 + (c * PichY) + aay
                            y2 = y1 + dyhh
                            If c <> mmm Then ady = 1 Else ady = 0
                            '---------------------------------------------
                            If MakeNewColorData Then
                                ccc = RGB(CRR, CGG, CBB)
                                cColors(idx) = ccc
                            Else
                                ccc = cColors(idx)
                            End If
                            '---------------------------------------------
                            brs = CreateSolidBrush(ccc)
                            If brs <> 0 Then
                                old = SelectObject(hDC, brs)
                                If old <> 0 Then
                                    gggint = SetRect(rc, x1, y1, x2 + adx, y2 + ady)
                                    gggint = FillRect(hDC, rc, brs)
                                    gggint = SelectObject(hDC, old)
                                    old = 0
                                End If
                                gggint = DeleteObject(brs)
                                brs = 0
                            End If
                            '---------------------------------------------
                            idx += 1
                            '---------------------------------------------
                        Next
                    Next
                Next
            End If
            ''***************************************************************
            'Static mChkCount As Integer
            'mChkCount = mChkCount + 1 : qqqqq(Format(mChkCount, "0000") + "●●  SizeNewSet MainBoxDraw")
            ''***************************************************************
Goto_c原因再計算と中心部の描画は不要:
            '***************************************************************
            gggbol = zzグラデ領域描画すぐに(hDC, True)
            '***************************************************************
            Dim フォーカス枠現在の色 As Integer : Dim rctmp As RECT
            If Me.Enabled Then フォーカス枠現在の色 = OutSideLineColor Else フォーカス枠現在の色 = &HA0A0A0
            gggbol = ⅩFrameDraw(hDC, rctmp, フォーカス枠現在の色, フォーカスライン幅, 0, 0, mImgWD, mImgHT, 色をぼかす)
            '***************************************************************
Goto_m原因クリック_5_6_ボタン_UP:
            Dim nnnn As Integer
            For nnnn = 5 To 6
                gggbol = zzBtnDraw(hDC, True, nnnn, CurColor, 色をぼかす)
            Next
            '***************************************************************
            Dim propstr As String = ":"
            If old_Enabled <> Enabled Then propstr = propstr & "Enabled" & ":"
            If old_GradationBoxSize <> GradationBoxSize Then propstr = propstr & "GradationBoxSize" & ":"
            If old_GradationPich <> GradationPich Then propstr = propstr & "GradationPich" & ":"
            If old_MainPich234 <> MainPich234 Then propstr = propstr & "MainPich234" & ":"
            If old_FrameWidth <> FrameWidth Then propstr = propstr & "FrameWidth" & ":"
            If old_CellPichX <> CellPichX Then propstr = propstr & "CellPichX" & ":"
            If old_CellPichY <> CellPichY Then propstr = propstr & "CellPichY" & ":"
            '------------------------------------------------------------------------
            old_Enabled = Enabled
            old_GradationBoxSize = GradationBoxSize
            old_GradationPich = GradationPich
            old_MainPich234 = MainPich234
            old_FrameWidth = FrameWidth
            old_CellPichX = CellPichX
            old_CellPichY = CellPichY
            '------------------------------------------------------------------------
            If propstr <> ":" Then
                RaiseEvent OnPanelChanged(propstr, mCurMainColor, mCurColor)
            End If
            '***************************************************************
            'ボタン押し下げ　描画
            '***************************************************************
Goto_c原因クリック_5_6_ボタン_DN:
            '***************************************************************
            '2022/04/11 不要コードだが、ここまでのジャンプは必要
            '***************************************************************
            m描画呼び出し原因 = 0
            '***************************************************************
            Static mChkCount As Integer
            mChkCount = mChkCount + 1 : qqqqq(CStr(mChkCount) + "  zzDrawMain() out")
            '***************************************************************
            Return True
            '***************************************************************
        Catch ex As Exception
            MsgBox(ex.ToString)
            m描画呼び出し原因 = 0
            Return False
        End Try
    End Function
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private Function zz選択枠をセット(ByRef from_zzDrawMain As Boolean) As Boolean
        Dim c As Integer = CurMainColor()
        Dim wRR As Integer, wGG As Integer, wBB As Integer
        gggbol = Ⅹ色RGB値(c, wRR, wGG, wBB)
        Dim ccc As Color
        If wGG < 165 Then
            ccc = Color.Yellow
        Else
            ccc = Color.Red
        End If
        m枠.CurColor = ccc
        '---------------------------------------------------------
        Dim X, Y As Integer
        m選択枠の設定原因 = from_zzDrawMain
        mCurMainColor = zzColorValGetSetXY(2, mCurMainColor, 0, 0, X, Y) 'CurMainColor
        Dim ww As Integer = IIf(CellPichX < 7 Or CellPichY < 7, 1, 2)
        '-------------------------------------------------------------------------------
        gggbol = m枠.aa_位置サイズ_Set((X - 1), (Y - 1), CellPichX + 2, CellPichY + 2, ww)
        m枠.Visible = Me.Enabled
        Return True
    End Function
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private Function zzグラデ領域描画すぐに(ByRef hdc As Integer, ByVal Up状態 As Boolean) As Boolean
        If mPCB Is Nothing Then Return False
        If mPCB.Image Is Nothing Then Return False
        Dim RET As Boolean = False : Dim HDC_引数なし As Boolean = False : Dim grh As Graphics = Nothing : Dim 色をぼかす As Boolean = Not (Me.Enabled)
        Try
            If hdc = 0 Then
                HDC_引数なし = True
                grh = Graphics.FromImage(mPCB.Image)
                If grh IsNot Nothing Then
                    hdc = grh.GetHdc()
                End If
            End If
            If hdc <> 0 Then
                'CurMainColor 変更の描画
                'qqqqq("Goto_c原因再計算と中心部の描画は不要")
                Dim celxyxy, aaa, Divvv As Integer : Dim wグラデーション色配列(0) As Integer
                Dim nowCurMainColor As Integer = CurMainColor
                'qqqqq("前　" + CStr(nowCurMainColor))
                celxyxy = MainPich234 * MainPich234 * MainPich234
                Divvv = 2 * celxyxy / GradationPich
                If ⅩColorGradationAryByColor("RGB", nowCurMainColor, Divvv, wグラデーション色配列, celxyxy) Then '上のグラデーションボックス
                    For aaa = 1 To celxyxy : gggint = ⅩRectDraw(hdc, mRcGD上(aaa), wグラデーション色配列(aaa), 0, 0, 0, 0, 色をぼかす) : Next
                End If
                If ⅩColorGradationAryByColor("R", nowCurMainColor, Divvv, wグラデーション色配列, celxyxy) Then '右のグラデーションボックス
                    For aaa = 1 To celxyxy : gggint = ⅩRectDraw(hdc, mRcGD右(aaa), wグラデーション色配列(aaa), 0, 0, 0, 0, 色をぼかす) : Next
                End If
                If ⅩColorGradationAryByColor("G", nowCurMainColor, Divvv, wグラデーション色配列, celxyxy) Then '下のグラデーションボックス
                    For aaa = 1 To celxyxy : gggint = ⅩRectDraw(hdc, mRcGD下(aaa), wグラデーション色配列(aaa), 0, 0, 0, 0, 色をぼかす) : Next
                End If
                If ⅩColorGradationAryByColor("B", nowCurMainColor, Divvv, wグラデーション色配列, celxyxy) Then '左のグラデーションボックス
                    For aaa = 1 To celxyxy : gggint = ⅩRectDraw(hdc, mRcGD左(aaa), wグラデーション色配列(aaa), 0, 0, 0, 0, 色をぼかす) : Next
                End If
                'qqqqq("後　" + CStr(nowCurMainColor))
                '***************************************************************
                'CurColorの描画()                                        
                Dim nn As Integer
                For nn = 5 To 6
                    gggbol = zzBtnDraw(hdc, Up状態, nn, CurColor, 色をぼかす)
                Next
                For nn = 7 To 8
                    gggbol = ⅩRectDraw(hdc, mRects(nn), CurColor, 0, 0, 0, 0, 色をぼかす) '上左のサンプルボックス  '上右のサンプルボックス  '下右のサンプルボックス  '下左のサンプルボックス
                Next
                RET = True
                '***************************************************************
            End If
            If HDC_引数なし Then
                If grh IsNot Nothing Then
                    If hdc <> 0 Then grh.ReleaseHdc(hdc)
                    grh.Flush()
                    hdc = 0
                End If
            End If
            gggbol = zz選択枠をセット(True)
            mPCB.Refresh()
            Return RET
        Catch ex As Exception
            If grh IsNot Nothing Then
                If hdc <> 0 Then grh.ReleaseHdc(hdc)
                hdc = 0
            End If
            MsgBox(ex.Message)
            Return False
        End Try
    End Function
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private Function zzBtnDrawInImageすぐに(ByVal Up状態 As Boolean, ByVal ボタンID As Integer) As Boolean
        If mPCB.Image Is Nothing Then Return False
        Dim RET As Boolean = False
        Dim grh As Graphics = Graphics.FromImage(mPCB.Image)
        If grh IsNot Nothing Then
            Dim hdc As IntPtr = grh.GetHdc()
            If hdc <> 0 Then
                RET = zzBtnDraw(hdc, Up状態, ボタンID, CurColor, (Me.Enabled = False))
                grh.ReleaseHdc(hdc)
            End If
            grh.Flush()
        End If
        mPCB.Refresh()
        Return RET
    End Function
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private Function zzBtnDraw(ByVal hdc As Integer, ByVal Up状態 As Boolean, ByVal ボタンID As Integer, ByVal MainColor As Integer, ByVal 色をぼかす As Boolean) As Boolean
        If hdc = 0 Then Return False
        Dim ボタン枠幅 As Integer = Math.Max(1, (Math.Min(ⅩRect幅(mRects(ボタンID)), ⅩRect高(mRects(ボタンID))) \ 12))
        Dim 表色 As Integer = IIf(Up状態, MainColor, ⅩColorXOR(MainColor))
        Dim 枠色 As Integer = ⅩColorXOR(表色)
        gggbol = ⅩRectDraw(hdc, mRects(ボタンID), 表色, 0, 0, 0, 0, 色をぼかす) '上左のサンプルボックス  '上右のサンプルボックス  '下右のサンプルボックス  '下左のサンプルボックス
        If Not 色をぼかす Then gggbol = ⅩFrameDraw(hdc, mRects(ボタンID), 枠色, ボタン枠幅, 0, 0, 0, 0, 色をぼかす)
        Return True
    End Function
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private Function zzColorValGetSetXY(ByVal op As Integer, ByRef rwColor As Integer, ByVal RX As Integer, ByVal RY As Integer, ByRef wdgX As Integer, ByRef wdgY As Integer) As Integer
        'rwColor は　Integer　モード　( Win32 COLORREF )
        'カラーセルの描画とデーター取得
        'op = 1  　RX, RY からカラー値を得る。
        'op = 2    カラー値からもつとも近い　rwX, rwY　を得る
        Dim CGG, CRR, CBB, n, b, a, c As Integer
        Dim BoxNum, x1, y1, PichX, PichY, ColorStep As Integer
        x1 = RX - mRects(0).lll : y1 = RY - mRects(0).ttt
        PichX = CellPichX : PichY = CellPichY
        BoxNum = MainPich234 * MainPich234
        ColorStep = CShort(255 / (BoxNum - 1))
        Select Case op
            Case 1
                a = (x1 Mod (BoxNum * PichX)) \ PichX
                CGG = Ⅹ数値範囲Int(0, 255, a * ColorStep)
                wdgX = mRects(0).lll + (x1 \ PichX) * PichX
                wdgX = Ⅹ数値範囲Int(mRects(0).lll, mRects(0).rrr - PichX, wdgX)
                a = (y1 Mod (BoxNum * PichY)) \ PichY
                CBB = Ⅹ数値範囲Int(0, 255, a * ColorStep)
                wdgY = mRects(0).ttt + (y1 \ PichY) * PichY
                wdgY = Ⅹ数値範囲Int(mRects(0).ttt, mRects(0).bbb - PichY, wdgY)
                a = x1 \ (BoxNum * PichX)
                b = y1 \ (BoxNum * PichY)
                n = a + (b * MainPich234)
                CRR = Ⅹ数値範囲Int(0, 255, n * ColorStep)
                rwColor = RGB(CRR, CGG, CBB)
                Return rwColor
            Case 2
                If Not Ⅹ色RGB値(rwColor, CRR, CGG, CBB) Then Exit Function
                a = CShort(CRR / ColorStep)
                n = a \ MainPich234
                wdgX = BoxNum * (a - (n * MainPich234))
                wdgY = BoxNum * n
                CRR = Ⅹ数値範囲Int(0, 255, ColorStep * a)
                b = CShort(CGG / ColorStep)
                wdgX = wdgX + b
                CGG = Ⅹ数値範囲Int(0, 255, ColorStep * b)
                c = CShort(CBB / ColorStep)
                wdgY = wdgY + c
                CBB = Ⅹ数値範囲Int(0, 255, ColorStep * c)
                wdgX = wdgX * PichX
                wdgY = wdgY * PichY
                wdgX = Ⅹ数値範囲Int(mRects(0).lll, mRects(0).rrr - PichX + 1, mRects(0).lll + wdgX)
                wdgY = Ⅹ数値範囲Int(mRects(0).ttt, mRects(0).bbb - PichY + 1, mRects(0).ttt + wdgY)
                Return RGB(CRR, CGG, CBB)
        End Select
        Return -1
        'Debug.Print CStr(Color999PaletOp)
    End Function
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
#End Region

#Region "from 五basCOM *****************************************************************"

#Region "WinAPI"
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Integer) As Integer
    Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Integer, ByVal hDC As Integer) As Integer
    <StructLayout(LayoutKind.Sequential)> Structure RECT
        Public lll As Integer
        Public ttt As Integer
        Public rrr As Integer
        Public bbb As Integer
    End Structure
    Private Declare Function SetRect Lib "user32" (ByRef lpRect As RECT, ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer) As Integer
    Private Declare Function CopyRect Lib "user32" Alias "CopyRect" (ByRef lpDestRect As RECT, ByRef lpSourceRect As RECT) As Integer
    Private Declare Function InflateRect Lib "user32" Alias "InflateRect" (ByRef lpRect As RECT, ByVal x As Integer, ByVal y As Integer) As Integer
    Private Declare Function IsRectEmpty Lib "user32" Alias "IsRectEmpty" (ByRef lpRect As RECT) As Integer
    Private Declare Function SetRectEmpty Lib "user32" Alias "SetRectEmpty" (ByRef lpRect As RECT) As Integer
    Private Declare Function FillRect Lib "user32" (ByVal hDC As Integer, ByRef lpRect As RECT, ByVal hBrush As Integer) As Integer
    Private Declare Function FrameRect Lib "user32" (ByVal hDC As Integer, ByRef lpRect As RECT, ByVal hBrush As Integer) As Integer
    Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Integer) As Integer
    Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Integer) As Integer
    Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Integer) As Integer
    Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer) As Integer
#End Region

#Region "変数と定数とEnum"
    Private gggCR2 As String = vbCrLf & vbCrLf
    Private gggbol As Boolean        '2022/03/07　　全コードで共有するテンポラリー戻り値。　Boolean型  で共用。
    Private gggint As Integer        '2022/03/07　　全コードで共有するテンポラリー戻り値。　Integer型  で共用。
    Private gggsng As Single
#End Region

#Region "基本"
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function qqqqq(ByVal s As String) As Boolean
        'Debug.Print 専用の関数　2012/05/05 new
        Debug.Print(s) : Return True
    End Function
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function Ⅹ数値範囲Int(ByVal dmin As Integer, ByVal dmax As Integer, ByVal dcheck As Integer) As Integer
        Dim a, a0 As Integer : Dim a1 As Integer
        If dmin < dmax Then
            a0 = dmin : a1 = dmax
        Else
            a0 = dmax : a1 = dmin
        End If
        a = dcheck
        If a > a1 Then a = a1
        If a < a0 Then a = a0
        Return a
    End Function
#End Region

#Region "描画"
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function ⅩColorGradationAryByColor(ByVal OpCodeRGB As String, ByVal r中心色 As Integer, ByVal Div As Integer, ByRef wグラデーション色配列() As Integer, ByVal rグラデーション色配列IDX_1_to_max As Integer) As Boolean
        '2021/03/21 chg   2014/12/14 new code
        'OpCodeRGB に　"R"  "G"  "B"　が入っていれば、ソレゾレの要素だけをグラデーションする。通常は　"RGB"　を指定する。
        'r中心色 からグラデーションセルのデーターを設定して配列  wグラデーション色配列(1 - wグラデーション色配列IDX_1_to_max)  に入れる。有効なインデックスは  1 To wグラデーション色配列IDX_1_to_max
        'Div でグラデーションのコントラストを指定する。
        Dim gg, rr, bb As Integer
        Dim CGG, n, a, c, CRR, CBB As Integer, ddivv As Single, ddivv11 As Single
        Dim e As Boolean
        Dim DoGG, DoRR, DoBB As Boolean
        ReDim wグラデーション色配列(rグラデーション色配列IDX_1_to_max)
        If Not Ⅹ色RGB値(r中心色, rr, gg, bb) Then Return False
        ReDim wグラデーション色配列(rグラデーション色配列IDX_1_to_max)
        n = rグラデーション色配列IDX_1_to_max \ 2
        DoRR = (InStr(OpCodeRGB, "R") > 0)
        DoGG = (InStr(OpCodeRGB, "G") > 0)
        DoBB = (InStr(OpCodeRGB, "B") > 0)
        '2022/11/20
        For a = 1 To rグラデーション色配列IDX_1_to_max
            e = (a <= n)
            c = IIf(e, n - a, a - n)
            ddivv = c / Div
            ddivv11 = (1 - ddivv)
            If DoRR Then CRR = Ⅹ数値範囲Int(0, 255, IIf(e, rr * ddivv11, rr + ((255 - rr) * ddivv))) Else CRR = rr
            If DoGG Then CGG = Ⅹ数値範囲Int(0, 255, IIf(e, gg * ddivv11, gg + ((255 - gg) * ddivv))) Else CGG = gg
            If DoBB Then CBB = Ⅹ数値範囲Int(0, 255, IIf(e, bb * ddivv11, bb + ((255 - bb) * ddivv))) Else CBB = bb
            wグラデーション色配列(a) = RGB(CRR, CGG, CBB)
        Next
        'qqqqq("zzColorGradationAryByColor out")
        Return True
    End Function
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function ⅩColor_to_INT(ByVal Color構造体 As Color) As Integer
        Return System.Drawing.ColorTranslator.ToWin32(Color構造体)
    End Function
    Private Function ⅩColor_from_INT(ByVal 色 As Integer) As Color
        Return System.Drawing.ColorTranslator.FromWin32(色)
    End Function
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function ⅩColor構造体_to_色値(ByVal Color構造体 As Color) As Integer
        Return System.Drawing.ColorTranslator.ToWin32(Color構造体)
    End Function
    Private Function ⅩColor構造体_from_色値(ByVal 色 As Integer) As Color
        Return System.Drawing.ColorTranslator.FromWin32(色)
    End Function
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function Ⅹ色システム色をLong値に変換(ByVal SysColorIndex As Integer) As Integer
        Return GetSysColor(Ⅹ数値範囲Int(0, &H18, System.Math.Abs(&H80000000 - SysColorIndex)))
    End Function
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function ⅩColorXOR(ByVal rColor As Integer) As Integer
        Dim ccc As Integer = Ⅹ色LONG値(rColor)
        Return Ⅹ数値範囲Int(0, &HFFFFFF&, &HFFFFFF& Xor ccc)
    End Function
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function Ⅹ色LONG値(ByVal ColorValOrIndex As Integer) As Integer
        'ColorValOrIndex = カラー実効値あるいはシステムカラーインデックス
        Dim c As Integer
        c = Ⅹ色の値の検査修正値(ColorValOrIndex)
        If c >= 0 And c <= &HFFFFFF Then Return c Else Return Ⅹ色システム色をLong値に変換(c)
    End Function
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function Ⅹ色RGB値(ByVal ColorValOrIndex As Integer, ByRef wRR As Integer, ByRef wGG As Integer, ByRef wBB As Integer) As Boolean
        'ColorValOrIndex = カラー実効値あるいはシステムカラーインデックス
        Dim c As Integer = Ⅹ色LONG値(ColorValOrIndex)
        wBB = (c And &HFF0000) \ &H10000
        wGG = (c And &HFF00) \ &H100S
        wRR = (c And &HFF)
        Return True
    End Function
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function Ⅹ色の値の検査修正値(ByVal ColorValOrIndex As Integer) As Integer
        'ColorValOrIndex = カラー実効値あるいはシステムカラーインデックス
        If ColorValOrIndex < 0 Then
            If ColorValOrIndex > &H80000018 Then
                Return &H80000018
            ElseIf ColorValOrIndex < &H80000000 Then
                Return &H80000000
            Else
                Return ColorValOrIndex
            End If
        Else
            If ColorValOrIndex > &HFFFFFF Then Return &HFFFFFF Else Return ColorValOrIndex
        End If
    End Function
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function Ⅹ色をぼかすOnEnabledOff(ByVal rEnabled As Boolean, ByVal ColorValOrIndex As Integer) As Integer
        Dim gg, rr, bb As Integer
        If rEnabled Then
            Return Ⅹ色LONG値(ColorValOrIndex)
        Else
            gggint = Ⅹ色RGB値(ColorValOrIndex, rr, gg, bb)
            Return RGB(rr + (255 - rr) \ 2, gg + (255 - gg) \ 2, bb + (255 - bb) \ 2)
        End If
    End Function
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function ⅩFrameDraw(ByVal hDC As Integer, ByRef rc As RECT, ByVal color As Integer, ByVal LineWD As Integer, ByVal left As Integer, ByVal Top As Integer, ByVal wd As Integer, ByVal ht As Integer, ByVal 色をぼかす_Enabled_Off As Boolean) As Boolean
        If hDC = 0 Then Return False
        If LineWD < 1 Then Return False
        Dim RET As Boolean = False, old As Integer = 0, brs As Integer = 0, ccc As Integer = 0, wRect As RECT
        Try
            If False = ⅩRectCopyOrMake(wRect, rc, left, Top, wd, ht) Then Return False
            If 色をぼかす_Enabled_Off Then ccc = Ⅹ色をぼかすOnEnabledOff(False, color) Else ccc = color
            brs = CreateSolidBrush(Ⅹ色LONG値(color))
            If brs <> 0 Then
                old = SelectObject(hDC, brs)
                If old <> 0 Then
                    Dim n, a, www, hhh As Integer
                    With wRect : www = .rrr - .lll : hhh = .bbb - .ttt : End With
                    n = Math.Min((Math.Min(www, hhh) \ 2), LineWD)
                    For a = 0 To n - 1
                        RET = (0 <> FrameRect(hDC, wRect, brs))
                        gggint = InflateRect(wRect, -1, -1)
                    Next
                    gggint = SelectObject(hDC, old) : old = 0
                End If
                gggint = DeleteObject(brs) : brs = 0
            End If
        Catch
            If old <> 0 Then gggint = SelectObject(hDC, old)
            If brs <> 0 Then gggint = DeleteObject(brs)
        End Try
        Return RET
    End Function
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function ⅩRect幅(ByRef rc As RECT) As Integer
        Return rc.rrr - rc.lll
    End Function
    Private Function ⅩRect高(ByRef rc As RECT) As Integer
        Return rc.bbb - rc.ttt
    End Function
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function ⅩRect内にXY座標がある(ByVal X As Integer, ByVal Y As Integer, ByRef rc As RECT) As Boolean
        Return (X >= rc.lll And X < rc.rrr And Y >= rc.ttt And Y < rc.bbb)
    End Function
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function ⅩRectCopyOrMake(ByRef wRect As RECT, ByRef rc As RECT, ByVal left As Integer, ByVal Top As Integer, ByVal wd As Integer, ByVal ht As Integer) As Boolean
        'wRect に　left, Top, wd, ht が有効であれば、それらを設定する。　でなければ　wRect に　rc　を　コピーする。
        gggint = SetRectEmpty(wRect)
        If left >= 0 And Top >= 0 And wd > 0 And ht > 0 Then
            Dim x2 As Integer = left + wd
            Dim y2 As Integer = Top + ht
            If x2 > left And y2 > Top Then gggint = SetRect(wRect, left, Top, x2, y2)
        Else
            gggint = CopyRect(wRect, rc)
        End If
        Return (IsRectEmpty(wRect) = 0)
    End Function
    '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
    Private Function ⅩRectDraw(ByVal hDC As Integer, ByRef rc As RECT, ByVal color As Integer, ByVal left As Integer, ByVal top As Integer, ByVal wd As Integer, ByVal ht As Integer, ByVal 色をぼかす_Enabled_Off As Boolean) As Boolean
        If hDC = 0 Then Return False
        Dim RET As Boolean = False, hbr As Integer = 0, ccc As Integer, wRect As RECT
        Try
            If False = ⅩRectCopyOrMake(wRect, rc, left, top, wd, ht) Then Return False
            If 色をぼかす_Enabled_Off Then ccc = Ⅹ色をぼかすOnEnabledOff(False, color) Else ccc = color
            hbr = CreateSolidBrush(Ⅹ色LONG値(ccc))
            If hbr <> 0 Then
                RET = (0 <> FillRect(hDC, wRect, hbr))
                gggint = DeleteObject(hbr)
            End If
            hbr = 0
        Catch
            If hbr <> 0 Then gggint = DeleteObject(hbr)
            qqqqq("ERROR  in  ⅩRectDraw()")
        End Try
        Return RET
    End Function
#End Region

#End Region

#Region "from Class Wakuwaku *********************************************************"

    Private Class my五clsWakuwaku '

        Implements IDisposable

#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
        '-------------------------------------------------------------------------------
        Private disposed As Boolean = False
#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
            Dim b As Boolean
            b = zzNewLabelMake(rParent, mBar(0), rLineColor)
            b = zzNewLabelMake(rParent, mBar(1), rLineColor)
            b = zzNewLabelMake(rParent, mBar(2), rLineColor)
            b = zzNewLabelMake(rParent, mBar(3), rLineColor)
            LineWidth = rLineWD
            CurColor = rLineColor
            Return True
        End Function
        Private 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
        Public Overloads Sub Dispose() Implements IDisposable.Dispose
            If Me.disposed = True Then Return
            Dim b As Boolean = aa_Delete()
            Me.disposed = True
            GC.SuppressFinalize(Me)
        End Sub
        Protected Overrides Sub Finalize()
            Me.Dispose()
            MyBase.Finalize()
            Debug.Print("my五clsWakuwaku.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, ByVal r特別なライン幅 As Integer) 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

#End Region

End Class
