Option Strict Off
Option Explicit On
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.ComponentModel

'2024/08/13 *************************************************************************************

Public Class 五clsColorSetUa

#Region "使用方法について"
    '簡単なカラーパレットを作り、マウスイベントでカラー値を取得。
    '色見本のモード  4*4*4  9*9*9  16*16*16  を実行中に変更可能。
    'カラーの値はすべて、 Win32 COLOREF(Integer) 値を使用。  64 Bit OS が前提条件　//　32 Bit OS では　Win32 COLOREF(Long)　に変更
    'カラーの値の　NET System.Drawing.Color との変換は下記の関数を使用。
    'Color   = Me.CboxColor_from_INT(ByRef Win32COLOREF As Integer) 
    'Integer = Me.CboxColor_to_INT(ByRef Color構造体 As Color) 
#End Region

#Region "五clsColorSetUa  を直接に使用して　Form 内にカラーボックスを作成する方法"
    ''--------------------------------------------------------------------------
    ''宣言
    'Private WithEvents o色見本 As 五clsColorSetUa = Nothing
    'Private wflg_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 五clsColorSetUa(wflg_o色見本Loading, rParent_As_Control)
    '                                '● Me Location / Size in rParent = 20, 20, 260, 260 ... All Propertys Set Default
    '    'あるいは ...
    '    o色見本 = New 五clsColorSetUa(wflg_o色見本Loading, rParent_As_Control, rサイズ設定用ラベル_As_Label, _
    '                                Optional_rEnabled_As_Boolean    True, _
    '                                Optional_rMainPich234_As_EnmCboxMainPich    五clsColorSetUa.EnmCboxMainPich.Pich3, _
    '                                Optional_rGradationBoxSize_As_EnmGradationBoxSize    五clsColorSetUa.EnmGradationBoxSize.GBS3, _
    '                                Optional_rGradationType_As_EnmCboxGradationType    五clsColorSetUa.EnmCboxGradationType.g2, _
    '                                Optional_rFrameWidth_As_EnmFrameWidth    五clsColorSetUa.EnmFrameWidth.FRMW3, _
    '                                Optional_rOutSideLineWidth_As_EnmOutSideLineWidth    五clsColorSetUa.EnmOutSideLineWidth.OSLW3, _
    '                                Optional_rOutSideLineColor_As_Intege    &HFF0000&, _
    '                                Optional_rCurMainColor_As_Integer    &HC0C0C0)
    '                                '● Me Location / Size in rParent = rサイズ設定用ラベル Location / Size
    '    'あるいは ...
    '    o色見本 = New 五clsColorSetUa(wflg_o色見本Loading, rParent_As_Control, rLeft_As_Integer, rTop_As_Integer, rWidth_As_Integer, rHeight_As_Integer, _
    '                                Optional_rEnabled_As_Boolean    True, _
    '                                Optional_rMainPich234_As_EnmCboxMainPich    五clsColorSetUa.EnmCboxMainPich.Pich3, _
    '                                Optional_rGradationBoxSize_As_EnmGradationBoxSize    五clsColorSetUa.EnmGradationBoxSize.GBS3, _
    '                                Optional_rGradationType_As_EnmCboxGradationType    五clsColorSetUa.EnmCboxGradationType.g2, _
    '                                Optional_rFrameWidth_As_EnmFrameWidth    五clsColorSetUa.EnmFrameWidth.FRMW3, _
    '                                Optional_rOutSideLineWidth_As_EnmOutSideLineWidth    五clsColorSetUa.EnmOutSideLineWidth.OSLW3, _
    '                                Optional_rOutSideLineColor_As_Intege    &HFF0000&, _
    '                                Optional_rCurMainColor_As_Integer    &HC0C0C0)
    '                                '● Me Location / Size in rParent = rLeft, rTop, rWidth, rHeight
    '    '........
    '    '........
    '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色見本_OnCboxColorChanged(ByVal rCurMainColor As Integer, ByVal rCurColor As Integer, ByVal rChangeMode As UaFineConts.UaColorBox.EnmColorChangeMode, ByVal rEventMouseUp As Boolean) Handles o色見本.OnCboxColorChanged
    '　　'マウス異動、あるいは外部からの設定による、中心部の箱型領域内のインジケーターの移動で発生しする。
    '　　'外側四方のグラデーション領域内での、●マウス異動でも発生する。
    '    If wflg_o色見本Loading Then Exit Sub
    '    If rCurColor >= 0 Then
    '        Dim b as boolean = o色見本.CboxCurColorSetIntoControlBackOrFore(LabelSample, RadioButton背景の色.Checked, True)
    '    End If
    '    'Debug.Print("色見本_OnCboxColorChanged  " + CStr(rChangeMode) + "   " + CStr(rEventMouseUp))
    'End Sub
    ''--------------------------------------------------------------------------
    'Private Sub o色見本_OnCboxMainColorChanged(ByVal rCurMainColor As Integer, ByVal rCurColor As Integer, ByVal rChangeMode As UaFineConts.UaColorBox.EnmColorChangeMode, ByVal rEventMouseUp As Boolean) Handles o色見本.OnCboxMainColorChanged
    '　　'マウス異動、あるいは外部からの設定による、中心部の箱型領域内のインジケーターの移動で発生する。
    '　　'外側四方のグラデーション領域内での、●マウス異動では発生しない。
    '    If wflg_o色見本Loading Then Exit Sub
    '    'Debug.Print("o色見本_OnCboxMainColorChanged  " + CStr(rChangeMode) + "   " + CStr(rEventMouseUp))
    'End Sub
    ''--------------------------------------------------------------------------
    'Private Sub o色見本_OnCboxMainPich234Changed(ByVal CboxMainPich234 As UaFineConts.UaColorBox.EnmCboxMainPich, ByVal rCurMainColor As Integer) Handles o色見本.OnCboxMainPich234Changed
    '　　'カラーピッチが変更され、再描画された直後に発生する。
    '    If wflg_o色見本Loading Then Exit Sub
    '    'Debug.Print("o色見本_OnCboxMainPich234Changed")
    'End Sub
#End Region

#Region "Private 変数および定数"
    Const cサイズ最小 As Integer = 100
    Const cサイズ最大 As Integer = 4000
    Const c既定Left As Integer = 20
    Const c既定Top As Integer = 20
    Const c既定Width As Integer = 260
    Const c既定Height As Integer = 260
    '-------------------------------------------------------------------------------
    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 EnmColorChangeMode, mEventMouseUp As Boolean
    Private mImgWD As Integer = 0 : Private mImgHT As Integer = 0
    Private m枠 As 五clsWakuwaku = Nothing
    '-------------------------------------------------------------------------------
#End Region

#Region "発行するイベント"
    Enum EnmColorChangeMode As Integer
        外部からの設定 = 0
        マウス移動あるいはキー入力 = 1
        パネルモード234チェンジ = 2
        グラデーションチェンジ = 3
    End Enum
    'rEventMouseUp As Boolean    'マウスアップイベントの場合のみ True
    Event OnCboxMainColorChanged(ByVal rCurMainColor As Integer, ByVal rCurColor As Integer, ByVal rChangeMode As EnmColorChangeMode, ByVal rEventMouseUp As Boolean)    'rEventMouseUp As Boolean    'マウスアップイベントの場合のみ True
    Event OnCboxColorChanged(ByVal rCurMainColor As Integer, ByVal rCurColor As Integer, ByVal rChangeMode As EnmColorChangeMode, ByVal rEventMouseUp As Boolean)        'rEventMouseUp As Boolean    'マウスアップイベントの場合のみ True
    Event OnCboxPanelMakeEnd_NextCall_ResizeEvent(ByVal rCurMainColor As Integer)
    Event OnCboxFirstShown(ByVal rCurMainColor As Integer)
    Event OnCboxEnabledChanged(ByVal CboxEnabled As Boolean)
    Event OnCboxGradationBoxSizeChanged(ByVal CboxGradationBoxSize As Integer)
    Event OnCboxGradationTypeChanged(ByVal CboxGradationType As EnmCboxGradationType)
    Event OnCboxMainPich234Changed(ByVal CboxMainPich234 As EnmCboxMainPich, ByVal rCurMainColor As Integer)
#End Region

#Region "初期化とファイナル"
    '***************************************************************************************************************
#Region "Picturebox からの派生でコントロールを作成"
    Private mFlg描画禁止 As Boolean = False
    Friend Property Flg描画禁止() As Boolean
        Get
            Return mFlg描画禁止
        End Get
        Set(ByVal Value As Boolean)
            mFlg描画禁止 = Value
        End Set
    End Property
    Friend Function UaColorBox_PictureBox_New(ByVal rPCB As PictureBox, _
                            ByVal rEnabled As Boolean, ByVal rMainPich234 As EnmCboxMainPich, ByVal rGradationBoxSize As EnmGradationBoxSize, ByVal rGradationType As EnmCboxGradationType, _
                            ByVal rFrameWidth As EnmFrameWidth, ByVal rOutSideLineWidth As EnmOutSideLineWidth, ByVal rOutSideLineColor As Integer, ByVal rCurMainColor As Integer) As Boolean
        If rPCB Is Nothing Then
            MsgBox("ERROR in " & Me.ToString & ".New()" & vbCrLf & "MyBase コントロール ( PictureBox ) の指定が必要です。") : Return False
        End If
        mDoneColorBoxLoad = False
        With rPCB
            gggbol = zzBmpObjctsMake(.ClientRectangle.Width, .ClientRectangle.Height, rPCB)
        End With
        If mPCB IsNot Nothing Then
            Dim wflg_o色見本Loading As Boolean
            wflg_o色見本Loading = True
            gggbol = zzMake(True, mPCB.Left, mPCB.Top, mPCB.ClientRectangle.Width, mPCB.ClientRectangle.Height, rEnabled, rMainPich234, rGradationBoxSize, rGradationType, rFrameWidth, rOutSideLineWidth, rOutSideLineColor, rCurMainColor)
            wflg_o色見本Loading = False
            CboxCurMainColor = CboxCurMainColor
            Return True
        End If
        Return False
    End Function
    Friend Sub UaColorBox_SizeChanged()
        'qqqqq("** UaColorBox_SizeChanged " & CStr(mPCB.Width))
        If mPCB Is Nothing Then Return
        With mPCB
            gggbol = zzSetSizeDraw(2, .Left, .Top, .ClientRectangle.Width, .ClientRectangle.Height)
        End With
        If mDoneFirstShown = False Then
            mDoneFirstShown = True
            Dim c As Integer = CboxCurMainColor
            RaiseEvent OnCboxFirstShown(c)
        End If
    End Sub
#End Region
    '***************************************************************************************************************
#Region "クラスから直接作成する場合"
    Public Sub New()
        mDoneColorBoxLoad = False : mPCB = Nothing
    End Sub
    Public Sub New(ByRef wflg_o色見本Loading As Boolean, ByVal rParent As Control)
        gggbol = New_COM(wflg_o色見本Loading, rParent, c既定Left, c既定Top, c既定Width, c既定Height, mEnabled, mMainPich234, mGradationBoxSize, mGradationType, mFrameWidth, mOutSideLineWidth, mOutSideLineColor, mCurMainColor)
    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 EnmCboxMainPich = EnmCboxMainPich.Pich3, _
                                    Optional ByVal rGradationBoxSize As EnmGradationBoxSize = EnmGradationBoxSize.GBS3, _
                                    Optional ByVal rGradationType As EnmCboxGradationType = EnmCboxGradationType.g2, _
                                    Optional ByVal rFrameWidth As EnmFrameWidth = EnmFrameWidth.FRMW3, _
                                    Optional ByVal rOutSideLineWidth As EnmOutSideLineWidth = EnmOutSideLineWidth.OSLW3, _
                                    Optional ByVal rOutSideLineColor As Integer = &HFF0000&, _
                                    Optional ByVal rCurMainColor As Integer = &HC0C0C0)
        If rサイズ設定用ラベル Is Nothing Then
            MsgBox("ERROR in " & Me.ToString & ".New()" & vbCrLf & "サイズ設定用ラベル ( Label ) の指定が必要です。") : Return
        End If
        With rサイズ設定用ラベル
            .Visible = False
            gggbol = New_COM(wflg_o色見本Loading, rParent, .Left, .Top, .Width, .Height, rEnabled, rMainPich234, rGradationBoxSize, rGradationType, rFrameWidth, rOutSideLineWidth, rOutSideLineColor, rCurMainColor)
        End With
    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 EnmCboxMainPich = EnmCboxMainPich.Pich3, _
                                    Optional ByVal rGradationBoxSize As EnmGradationBoxSize = EnmGradationBoxSize.GBS3, _
                                    Optional ByVal rGradationType As EnmCboxGradationType = EnmCboxGradationType.g2, _
                                    Optional ByVal rFrameWidth As EnmFrameWidth = EnmFrameWidth.FRMW3, _
                                    Optional ByVal rOutSideLineWidth As EnmOutSideLineWidth = EnmOutSideLineWidth.OSLW3, _
                                    Optional ByVal rOutSideLineColor As Integer = &HFF0000&, _
                                    Optional ByVal rCurMainColor As Integer = &HC0C0C0)
        gggbol = New_COM(wflg_o色見本Loading, rParent, rLeft, rTop, rWidth, rHeight, rEnabled, rMainPich234, rGradationBoxSize, rGradationType, rFrameWidth, rOutSideLineWidth, rOutSideLineColor, rCurMainColor)
    End Sub
    Private Function New_COM(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, _
                             ByVal rEnabled As Boolean, ByVal rMainPich234 As EnmCboxMainPich, ByVal rGradationBoxSize As EnmGradationBoxSize, ByVal rGradationType As EnmCboxGradationType, _
                             ByVal rFrameWidth As EnmFrameWidth, ByVal rOutSideLineWidth As EnmOutSideLineWidth, ByVal rOutSideLineColor As Integer, ByVal rCurMainColor As Integer) As Boolean
        mDoneColorBoxLoad = False
        If rParent Is Nothing Then
            MsgBox("ERROR in " & Me.ToString & ".New(....)" & vbCrLf & "親コントロール ( rParent As Control ) の指定が必要です。") : Return False
        End If
        gggbol = zzBmpObjctsMake(rWidth, rHeight)
        If mPCB IsNot Nothing Then mPCB.Parent = rParent Else Return False
        wflg_o色見本Loading = True
        gggbol = zzMake(True, rLeft, rTop, rWidth, rHeight, rEnabled, rMainPich234, rGradationBoxSize, rGradationType, rFrameWidth, rOutSideLineWidth, rOutSideLineColor, rCurMainColor)
        CboxCurMainColor = rCurMainColor
        wflg_o色見本Loading = False
        Return True
    End Function
#End Region
    '***************************************************************************************************************
    Public Sub Dispose()
        If Not mPCB Is Nothing Then Call zzBmpObjctsDel()
        mPCB = Nothing
    End Sub
    Protected Overrides Sub Finalize()
        If Not mPCB Is Nothing Then Call zzBmpObjctsDel()
        mPCB = Nothing
        MyBase.Finalize()
    End Sub
    Private Sub mPCB_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles mPCB.Disposed
        'qqqqq(Me.ToString & ".mPCB_Disposed()")
    End Sub
#End Region

#Region "Private 関数"
    Private Function zzMake(ByRef wflg_o色見本Loading As Boolean, _
                            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 EnmCboxMainPich = EnmCboxMainPich.Pich3, _
                            Optional ByVal rGradationBoxSize As EnmGradationBoxSize = EnmGradationBoxSize.GBS3, _
                            Optional ByVal rGradationType As EnmCboxGradationType = EnmCboxGradationType.g2, _
                            Optional ByVal rFrameWidth As EnmFrameWidth = EnmFrameWidth.FRMW3, _
                            Optional ByVal rOutSideLineWidth As EnmOutSideLineWidth = EnmOutSideLineWidth.OSLW3, _
                            Optional ByVal rOutSideLineColor As Integer = &HFF0000&, _
                            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 zzMake()")
        Dim RET As Boolean = False
        wflg_o色見本Loading = True
        Try
            If mPCB Is Nothing Then Return False
            CboxEnabled = rEnabled                              'カラーボックス全体の Enabled　 False では淡色の表示になる。
            CboxMainPich234 = rMainPich234                      'カラーボックス全体のセルの縦横の数　　2 ～ 4　全セル数は、 (CboxMainPich234 * CboxMainPich234) の３乗 になる。
            CboxGradationBoxSize = rGradationBoxSize            'グラデーションボックス幅の、カラーボックス全体のサイズに対する、パーセント比率
            CboxGradationType = rGradationType                  'グラデーションの変化の強弱   1 ～ 3
            CboxFrameWidth = rFrameWidth                        'カラー領域の外縁の白い枠の幅。                   全体の縦横サイズの小さい値の、1/1000 単位の値。 5 ～ 100
            CboxOutSideLineWidth = rOutSideLineWidth            'カラーボックス全体を囲むフォーカス表示枠の太さ。  全体の縦横サイズの小さい値の、1/1000 単位の値。 5 ～ 100
            CboxOutSideLineColor = rOutSideLineColor            'このコントロールの外枠の色。 ( Win32 COLOREF値 Integer )
            CboxCurMainColor = rCurMainColor                    '最初に表示されるときに選択するカラーの値 ( Win32 COLOREF値 Integer )
            If Not zzSetSizeDraw(1, rLeft, rTop, rWidth, rHeight) Then
                gggbol = m枠.aa_Delete() : m枠 = Nothing
                mPCB.Dispose() : mPCB = Nothing
                Return False
            End If
            RET = (mPCB IsNot Nothing)
        Catch ex As Exception
            MsgBox("ERROR in Make_1_Del_2()" & gggCR2 & ex.ToString)
            RET = False
        End Try
        wflg_o色見本Loading = False
        Return RET
    End Function
    Private Function zzBmpObjctsMake(ByVal rWidth As Integer, ByVal rHeight As Integer, Optional ByVal PCB As PictureBox = Nothing) As Boolean
        mPCB = PCB
        If mPCB Is Nothing Then
            mPCB = New PictureBox
        End If
        If Not mPCB Is Nothing Then
            With mPCB
                .BorderStyle = Windows.Forms.BorderStyle.None
                .SizeMode = PictureBoxSizeMode.Normal
                .Image = New Bitmap(rWidth, rHeight)
                If Not .Image Is Nothing Then
                    m枠 = New 五clsWakuwaku
                    If m枠.aa_Make(mPCB, 1, Color.Red) Then
                        If m枠.aa_BringToFront() Then
                            Return True
                        End If
                    End If
                End If
            End With
        End If
        gggbol = zzBmpObjctsDel()
        Return False
    End Function
    Private Function zzBmpObjctsDel() As Boolean
        If mPCB IsNot Nothing Then
            If m枠 IsNot Nothing Then
                gggbol = m枠.aa_Delete()
                m枠 = Nothing
            End If
            If mPCB IsNot Nothing Then
                mPCB.Dispose()
                mPCB = Nothing
            End If
        End If
        Return True
    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
        If mPCB Is Nothing Then Return False
        Select Case Make1_ReSize2_Draw3
            Case 1, 2
                'Size Chang or New Make
                Dim w As Integer = 2 * (Ⅹ数値範囲Int(cサイズ最小, cサイズ最大, rWidth) \ 2)
                Dim h As Integer = 2 * (Ⅹ数値範囲Int(cサイズ最小, cサイズ最大, rHeight) \ 2)
                With mPCB
                    If .Width <> w Or .Height <> h Then .SetBounds(Math.Max(0, rLeft), Math.Max(0, rTop), w, h, BoundsSpecified.All) ' .SetBounds(0, 0, w, h, BoundsSpecified.Size)
                    If .Image Is Nothing Then
                        'OK
                    ElseIf (.Image.Width <> w) Or (.Image.Height <> h) Then
                        .Image.Dispose()
                        .Image = Nothing
                    End If
                    If .Image Is Nothing Then
                        .Image = New Bitmap(w, h)
                    End If
                    m選択枠の設定原因 = False
                    CallCount += 1
                    'qqqqq(CStr(CallCount) & " ** in SetSizeDraw() -- Make New Image")
                End With
            Case 3
                'no op
        End Select
        If mPCB.Image Is Nothing Then Return False
        mDoneColorBoxLoad = True
        Return zzCboxReDrawDo(False)
    End Function
    Private 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
#End Region

#Region "Public 外部とのI/O関数"
    Public Function CboxReDraw() As Boolean
        Return zzCboxReDrawDo(True)
    End Function
    Private Function zzCboxReDrawDo(ByVal DoDrawAllWays As Boolean) As Boolean
        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 (Not DoDrawAllWays) And (m選択枠の設定原因 = True) Then
                    '描画は不要　選択枠　の移動に伴う　mPCB　の描画イベントで、mPCB.Image　には無関係で、そのままでよい。
                    m選択枠の設定原因 = False
                    'qqqqq("m選択枠の設定原因 = True")
                    RET = True
                Else
                    RET = zzDrawMain(hdc)
                End If
                grh.ReleaseHdc(hdc)
                mPCB.Refresh()
            End If
        End If
        Return RET
    End Function
    Public Sub CboxRefresh()
        If mPCB Is Nothing Then Return
        mPCB.Refresh()
    End Sub
    Public Function Cbox色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 Cbox色1色2は現在モードでの誤差範囲内で同じ(c1, c2)
    End Function
    Public Function Cbox色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 / (CboxMainPich234 * CboxMainPich234) / 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 CboxColor_to_INT(ByVal Color構造体 As Color) As Integer
        Return System.Drawing.ColorTranslator.ToWin32(Color構造体)
    End Function
    Public Function CboxColor_from_INT(ByVal IntVal色 As Integer) As Color
        Return System.Drawing.ColorTranslator.FromWin32(IntVal色)
    End Function
    Public Function CboxColorIntValHexStr(ByVal ColorINT As Integer) As String
        Return "&H" & Microsoft.VisualBasic.Right("00000000" & Hex(ColorINT), 8) & "&"
    End Function
    Public Function CboxCurColorAndTextSetIntoControl(ByRef wCont As Control, ByVal rSetTextColorIntVal As Boolean, ByVal rDoControlRefresh As Boolean) As Boolean
        Try
            With wCont
                Dim c As Integer = CboxCurColor
                .BackColor = CboxColor_from_INT(c)
                If rSetTextColorIntVal Then
                    .ForeColor = CboxHitBoxLineColorNow
                    .Text = CboxColorIntValHexStr(c)
                End If
                If rDoControlRefresh Then .Refresh()
            End With
            Return True
        Catch ex As Exception
            MsgBox("ERROR in UaColorBox.CurColorAndTextSetIntoControl() " & vbCrLf & vbCrLf & ex.ToString)
            Return False
        End Try
    End Function
    Public Function CboxCurColorSetIntoControlBackOrFore(ByRef wCont As Control, ByVal rSet_BackTrue_ForeFalse As Boolean, ByVal rDoControlRefresh As Boolean) As Boolean
        Try
            With wCont
                Dim ccc As Color = CboxColor_from_INT(CboxCurColor)
                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 UaColorBox.CurColorSetIntoControlBackOrFore() " & vbCrLf & vbCrLf & ex.ToString)
            Return False
        End Try
    End Function
    Public Sub CboxNewLocationSizeSet(ByVal rLeft As Integer, ByVal rTop As Integer, ByVal rWidth As Integer, ByVal rHight As Integer)
        If mPCB Is Nothing Then Return
        Dim c As Control = mPCB.Parent
        If c Is Nothing Then Return
        Dim w As Integer = 2 * (Ⅹ数値範囲Int(cサイズ最小, cサイズ最大, rWidth) \ 2)
        Dim h As Integer = 2 * (Ⅹ数値範囲Int(cサイズ最小, cサイズ最大, rHight) \ 2)
        '2024/0812 delete こちらで勝手に位置を移動すると、メニューあるいは他のコントロールの上にくる場合がある。 
        Dim x As Integer = rLeft 'Ⅹ数値範囲Int(0, c.ClientRectangle.Width - w, rLeft)
        Dim y As Integer = rTop  'Ⅹ数値範囲Int(0, c.ClientRectangle.Height - h, rTop)
        mPCB.SetBounds(x, y, w, h, BoundsSpecified.All)
    End Sub
#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, GradationType_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.CboxEnabled 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 五clsColorSetUa.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
                GradationType_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       '上左のボタン　パネルモード変更　　CboxMainPich234()
                        'Debug.Print Hex(CboxCurMainColor)
                        a = CboxMainPich234 + 1
                        If a > 4 Then CboxMainPich234() = 2 Else CboxMainPich234() = a 'ここで　 mPCB.Refresh()　が実行される
                        MainPich234_Change = True
                        'Debug.Print Hex(CboxCurMainColor): ccc = pcb.Point(shp.left + 1, shp.Top + 1): Debug.Print "*" + Hex(ccc)
                    ElseIf ⅩRect内にXY座標がある(X, Y, mRects(6)) Then   '上右のボタン  グラデーション変更
                        a = CboxGradationType + 1
                        'Debug.Print Hex(CboxCurMainColor):  Debug.Print "*" + Hex(CboxCurColor)
                        GradationType_Change = True
                        mChaneMode = EnmColorChangeMode.グラデーションチェンジ
                        If a > 3 Then CboxGradationType() = 1 Else CboxGradationType() = a
                        mChaneMode = EnmColorChangeMode.外部からの設定
                        'Debug.Print Hex(CboxCurMainColor):  Debug.Print "*" + Hex(CboxCurColor)
                    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 = EnmColorChangeMode.外部からの設定
                '-----------------------------------------------------------------------
            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(CboxCurMainColor) + ",  " + Hex(CboxCurColor)
        '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 = EnmColorChangeMode.マウス移動あるいはキー入力
                    'カラーパレットの状態により、指定された色がデジタイズされて返される。
                    CboxCurMainColor = zzColorValGetSetXY(2, cccnew, 0, 0, wdgX, wdgY)
                    mChaneMode = EnmColorChangeMode.外部からの設定
                ElseIf OnlySmpDraw Then
                    cccnew = ccc
                    mChaneMode = EnmColorChangeMode.マウス移動あるいはキー入力
                    CboxCurColor = ccc
                    mChaneMode = EnmColorChangeMode.外部からの設定
                End If
                m描画呼び出し原因 = 0
            End If
            Return cccnew
        End If
    End Function
    Private Function Color_to_INT(ByVal Color構造体 As Color) As Integer
        Return System.Drawing.ColorTranslator.ToWin32(Color構造体)
    End Function
#End Region

#Region "Public プロパティ"
    '<Description("カラーボックスが作成済みであれば　True　を返します。")> _
    Public ReadOnly Property CboxDoneColorBoxLoad() As Boolean
        Get
            Return mDoneColorBoxLoad
        End Get
    End Property
    Private mDoneColorBoxLoad As Boolean = False

    '<Description("カラーボックスが表示済みであれば　True　を返します。")> _
    Public ReadOnly Property CboxDoneFirstShown() As Boolean
        Get
            Return mDoneFirstShown
        End Get
    End Property
    Private mDoneFirstShown As Boolean = False

    '<Description("選択された色を囲む小さなフレームの、現在の色を取得します。( Color 構造体の値 )")> _
    Public ReadOnly Property CboxHitBoxLineColorNow() As Color
        Get
            Return m枠.CurColor
        End Get
    End Property

    '<Description("カラーボックス全体を囲む表示枠の色を、設定／取得します。( Hex0 ～ HexFFFFFF の Integer )")> _
    '<Browsable(True), _
    'EditorAttribute(GetType(UIEdColorDlg), GetType(System.Drawing.Design.UITypeEditor))> _
    Public Property CboxOutSideLineColor() As Integer
        Get
            Return mOutSideLineColor
        End Get
        Set(ByVal Value As Integer)
            mOutSideLineColor = Ⅹ色の値の検査修正値(Value)
            'qqqqq("CHANGE  CboxOutSideLineColor")
            gggbol = zzmPCB_WndAllRefresh()
        End Set
    End Property
    Private mOutSideLineColor As Integer = &HFF0000&

    '<Description("グラデーションボックスの、グラデーションの強弱を、設定／取得します。( EnmCboxGradationType.g1 ～ .g3 )")> _
    Public Property CboxGradationType() As EnmCboxGradationType
        Get
            Return mGradationType
        End Get
        Set(ByVal Value As EnmCboxGradationType)
            'qqqqq("CboxGradationType-1 " & CStr(CboxCurColor)) '2024/01/25 OK
            mGradationType = Ⅹ数値範囲Int(1, 3, Value)
            CboxCurColor = CboxCurMainColor
            'qqqqq("CboxGradationType-2 " & CStr(CboxCurColor)) '2024/01/25 OK
        End Set
    End Property
    Public Enum EnmCboxGradationType As Integer
        g1 = 1
        g2 = 2
        g3 = 3
    End Enum
    Private mGradationType As Integer = EnmCboxGradationType.g2

    '<Description("カラーボックス全体の Enabled を、設定／取得します。( False では淡色の表示になります。)")> _
    Public Property CboxEnabled() As Boolean
        Get
            Return mEnabled
        End Get
        Set(ByVal Value As Boolean)
            mEnabled = Value
            If mPCB IsNot Nothing Then mPCB.Enabled = Value
            'qqqqq("CHANGE  CboxEnabled")
            gggbol = zzmPCB_WndAllRefresh()
        End Set
    End Property
    Private mEnabled As Boolean = True

    '<Description("カラーボックス全体のセルの縦横の数を、設定／取得します。( EnmCboxMainPich.Pich2 ～ .Pich4 )")> _
    Public Property CboxMainPich234() As EnmCboxMainPich
        '全セル数は、 (CboxMainPich234 * CboxMainPich234) * (CboxMainPich234 * CboxMainPich234) * (CboxMainPich234 * CboxMainPich234)
        '            ( 4 * 4 * 4 or 9 * 9 * 9 or 16 * 16 * 16 ) になる。
        Get
            Return mMainPich234
        End Get
        Set(ByVal Value As EnmCboxMainPich)
            'qqqqq("CboxMainPich234-1 " & CStr(CboxCurMainColor)) '2024/01/25 OK
            mMainPich234 = Ⅹ数値範囲Int(2, 4, Value)
            'qqqqq("CHANGE  CboxMainPich234")
            gggbol = zzmPCB_WndAllRefresh()
            CboxCurColor = CboxCurMainColor
            'qqqqq("CboxMainPich234-2 " & CStr(CboxCurMainColor)) '2024/01/25 OK
        End Set
    End Property
    Public Enum EnmCboxMainPich As Integer
        Pich2 = 2
        Pich3 = 3
        Pich4 = 4
    End Enum
    Private mMainPich234 As Integer = EnmCboxMainPich.Pich3

    '<Description("現在のカラー  カラーセル内の選択ボックスの位置の色を、設定／取得します。( Hex0 ～ HexFFFFFF の Integer )")> _
    '<Browsable(True), _
    'EditorAttribute(GetType(UIEdColorDlg), GetType(System.Drawing.Design.UITypeEditor))> _
    Public Property CboxCurMainColor() As Integer
        '現在のカラー  カラーセルの中の選択ボックスのある位置の色
        Get
            Return mCurMainColor
        End Get
        '**********************************************************
        Set(ByVal Value As Integer)
            Dim c As Integer : Static OldPich As EnmCboxMainPich
            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 mDoneColorBoxLoad = False Then Return
                '------------------------------------------------------------
                If mPCB IsNot Nothing Then
                    m描画呼び出し原因 = c原因再計算と中心部の描画は不要
                    gggbol = zzグラデ領域描画すぐに(0, True)
                    m描画呼び出し原因 = 0

                    If OldPich <> CboxMainPich234 Then
                        mChaneMode = EnmColorChangeMode.パネルモード234チェンジ
                        OldPich = CboxMainPich234
                    End If

                    If OldColor <> mCurMainColor Or mEventMouseUp Then '2022/04/10 change
                        RaiseEvent OnCboxMainColorChanged(mCurMainColor, mCurMainColor, mChaneMode, mEventMouseUp)
                    End If
                End If
                '------------------------------------------------------------
                CboxCurColor = mCurMainColor
                '------------------------------------------------------------
            End If
            'Debug.Print("Let CboxCurMainColor() out  " & CStr(mChaneMode))
        End Set
    End Property
    Private mCurMainColor As Integer = &HC0C0C0

    '<Description("現在のカラー  グラデーションボックスで選択された色。あるいは、グラデーションボックスでの選択以前の CboxCurMainColor を、設定／取得します。( Hex0 ～ HexFFFFFF の Integer )")> _
    '<Browsable(True), _
    'EditorAttribute(GetType(UIEdColorDlg), GetType(System.Drawing.Design.UITypeEditor))> _
    Public Property CboxCurColor() As Integer
        '現在のカラー  グラデーションボックスで選択された色。あるいは、グラデーションボックスでの選択以前の CboxCurMainColor
        Get
            Return mCurColor
        End Get
        '**********************************************************
        Set(ByVal Value As Integer)
            Static ここから呼び出し As Boolean : Static OldPich As EnmCboxMainPich
            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 mDoneColorBoxLoad = False Then Return
                '------------------------------------------------------------
                If mPCB IsNot Nothing Then
                    m描画呼び出し原因 = c原因再計算と中心部の描画は不要
                    gggbol = zzグラデ領域描画すぐに(0, True)
                    m描画呼び出し原因 = 0

                    m選択枠の設定原因 = False
                    If OldColor <> mCurColor Or mEventMouseUp Then

                        'ここから呼び出し = True
                        'CboxCurMainColor = mCurColor
                        'mCurColor = mCurMainColor
                        'ここから呼び出し = False

                        '2024/07/30 chg ?????????????????????
                        If (mChaneMode <> EnmColorChangeMode.マウス移動あるいはキー入力 And mChaneMode <> EnmColorChangeMode.グラデーションチェンジ) Then
                            ここから呼び出し = True
                            CboxCurMainColor = mCurColor
                            mCurColor = mCurMainColor
                            ここから呼び出し = False
                        End If

                        If OldPich <> CboxMainPich234 Then
                            mChaneMode = EnmColorChangeMode.パネルモード234チェンジ
                            OldPich = CboxMainPich234
                        End If

                        RaiseEvent OnCboxColorChanged(mCurMainColor, mCurColor, mChaneMode, mEventMouseUp)
                        'Debug.Print(ColorIntValHexStr(mCurColor) & ",,," & ColorIntValHexStr(Color_to_INT(CboxHitBoxLineColorNow)))
                    End If
                End If
                '------------------------------------------------------------
                'Debug.Print("Let CboxCurColor() out  " & CStr(mChaneMode))
            End If
        End Set
    End Property
    Private mCurColor As Integer = &HC0C0C0

    '<Description("カラーボックス全体を囲む表示枠の太さ。")> _
    Public Property CboxOutSideLineWidth() As EnmOutSideLineWidth
        Get
            Return mOutSideLineWidth
        End Get
        Set(ByVal Value As EnmOutSideLineWidth)
            If mPCB Is Nothing Then Return
            Dim old As Integer = mOutSideLineWidth
            mOutSideLineWidth = Math.Min(EnmOutSideLineWidth.OSLW6, Math.Max(EnmOutSideLineWidth.OSLW1, Value))
            'qqqqq("CHANGE  CboxOutSideLineWidth")
            If (old <> mOutSideLineWidth) Then gggbol = zzmPCB_WndAllRefresh()
        End Set
    End Property
    Public Enum EnmOutSideLineWidth As Integer
        OSLW1 = 5
        OSLW2 = 8
        OSLW3 = 12
        OSLW4 = 17
        OSLW5 = 25
        OSLW6 = 38
    End Enum
    Private mOutSideLineWidth As EnmOutSideLineWidth = EnmOutSideLineWidth.OSLW3

    '<Description("カラーボックス全体を囲む表示枠の内側のフレームの太さ。")> _
    Public Property CboxFrameWidth() As EnmFrameWidth
        Get
            Return mFrameWidth
        End Get
        Set(ByVal Value As EnmFrameWidth)
            If mPCB Is Nothing Then Return
            Dim old As Integer = mFrameWidth
            mFrameWidth = Math.Min(EnmFrameWidth.FRMW6, Math.Max(EnmFrameWidth.FRMW1, Value))
            'qqqqq("CHANGE  CboxFrameWidth")
            If (old <> mFrameWidth) Then gggbol = zzmPCB_WndAllRefresh()
        End Set
    End Property
    Public Enum EnmFrameWidth As Integer
        FRMW1 = 5
        FRMW2 = 8
        FRMW3 = 12
        FRMW4 = 17
        FRMW5 = 25
        FRMW6 = 38
    End Enum
    Private mFrameWidth As EnmFrameWidth = EnmFrameWidth.FRMW3

    '<Description("グラデーションボックス幅の、セル群全体部分の幅に対する比率を、設定／取得します。")> _
    Public Property CboxGradationBoxSize() As EnmGradationBoxSize
        Get
            Return mGradationBoxSize
        End Get
        Set(ByVal Value As EnmGradationBoxSize)
            If mPCB Is Nothing Then Return
            Dim old As Integer = mGradationBoxSize
            mGradationBoxSize = Math.Min(EnmGradationBoxSize.GBS6, Math.Max(EnmGradationBoxSize.GBS1, Value))
            'qqqqq("CHANGE  CboxGradationBoxSize ")
            If (old <> mGradationBoxSize) Then gggbol = zzmPCB_WndAllRefresh()
        End Set
    End Property
    Public Enum EnmGradationBoxSize As Integer
        GBS1 = 6
        GBS2 = 9
        GBS3 = 12
        GBS4 = 16
        GBS5 = 22
        GBS6 = 30
    End Enum
    Private mGradationBoxSize As EnmGradationBoxSize = EnmGradationBoxSize.GBS3
#End Region

#Region "Private プロパティ"
    Private Property CellPichX() As Integer '<Description("１セルの X 方向のピクセル幅を、設定／取得します。全体のサイズに関連します。")>
        Get
            Return mCellPichX
        End Get
        Set(ByVal Value As Integer)
            '描画コード内で設定される。ここから描画を呼び出すと無限ループになる
            mCellPichX = Ⅹ数値範囲Int(1, cサイズ最大 / (CboxMainPich234 * CboxMainPich234 * CboxMainPich234), Value)
        End Set
    End Property
    Private mCellPichX As Integer = 2
    Private Property CellPichY() As Integer '<Description("１セルの Y 方向のピクセル幅を、設定／取得します。全体のサイズに関連します。")>
        '１セルピクセル高さ
        Get
            Return mCellPichY
        End Get
        Set(ByVal Value As Integer)
            '描画コード内で設定される。ここから描画を呼び出すと無限ループになる
            mCellPichY = Ⅹ数値範囲Int(1, cサイズ最大 / (CboxMainPich234 * CboxMainPich234 * CboxMainPich234), Value)
        End Set
    End Property
    Private mCellPichY As Integer = 2
#End Region

#Region "Private 描画関数"
    '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
    Private Function zzmPCB_WndAllRefresh() As Boolean
        If mDoneColorBoxLoad = False Then Return False
        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 ここから呼び出し As Boolean = False
        '-------------------------------------------------------------------------------
        Static old_Enabled As Boolean : Static old_GradationBoxSize As Integer : Static old_GradationType As Integer : Static old_MainPich234 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 ----------------------------------------------------------------
        '*******************************************************************************
        If ここから呼び出し Then Return True
        If Flg描画禁止 Then Return True
        '*******************************************************************************
        If mDoneColorBoxLoad = False Then Return False
        If mPCB Is Nothing Then Return False
        If hDC = 0 Then Return False
        '*******************************************************************************
        'gggbol = qqqqq("zzDrawMain() IN")
        '*******************************************************************************
        If mImgWD = mPCB.Image.Width Or mImgHT = mPCB.Image.Height Then
            m描画呼び出し原因 = 0
        End If
        mImgWD = mPCB.Image.Width
        mImgHT = mPCB.Image.Height
        ''2024/08/01 OK no error --------------------------------------------------------------------------
        'If mPCB.ClientRectangle.Width <> mImgWD Or mPCB.ClientRectangle.Height <> mImgHT Then
        '    qqqqq("ERROR mPCB.size <> mPCB.Image.Size")
        'End If
        ''2024/08/01 OK no error --------------------------------------------------------------------------
        '*******************************************************************************
        Try
            Dim nnn As Integer = Math.Min(mImgWD, mImgHT)
            Dim フォーカスライン幅 As Integer = Math.Max(2, nnn * (CboxOutSideLineWidth / 1000))
            Dim フレーム幅 As Integer = Math.Max(2, nnn * (CboxFrameWidth / 1000))
            Dim 幅幅 As Integer = フォーカスライン幅 + フレーム幅
            Dim 色をぼかす As Boolean = (Not Me.CboxEnabled)
            '*******************************************************************************
            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 = CboxMainPich234 * CboxMainPich234 * CboxMainPich234
                '-------------------------------------------------------------------------------
                Dim CellsAllWD As Integer = mImgWD - 幅幅 - 幅幅
                Dim CellsAllHT As Integer = mImgHT - 幅幅 - 幅幅
                Dim PichX As Integer = Int(CellsAllWD / (1 + 2 * (CboxGradationBoxSize / 100)) / cellxy)
                Dim PichY As Integer = Int(CellsAllHT / (1 + 2 * (CboxGradationBoxSize / 100)) / cellxy)
                If PichX < 1 Or PichY < 1 Then
                    qqqqq(CStr(PichX))
                    ここから呼び出し = True
                    CboxOutSideLineWidth = 5
                    フォーカスライン幅 = Math.Max(2, Math.Min(mImgWD, mImgHT) * CboxOutSideLineWidth \ 1000)
                    CboxFrameWidth = EnmFrameWidth.FRMW1
                    フレーム幅 = Math.Max(2, Math.Min(mImgWD, mImgHT) * CboxFrameWidth \ 1000)
                    幅幅 = フォーカスライン幅 + フレーム幅
                    CellsAllWD = mImgWD - 幅幅 - 幅幅
                    CellsAllHT = mImgHT - 幅幅 - 幅幅
                    CboxGradationBoxSize = EnmGradationBoxSize.GBS1
                    PichX = Int(CellsAllWD / (1 + 2 * (CboxGradationBoxSize / 100)) / cellxy)
                    PichY = Int(CellsAllHT / (1 + 2 * (CboxGradationBoxSize / 100)) / cellxy)
                    ここから呼び出し = False
                    qqqqq(CStr(PichX))
                End If
                '-------------------------------------------------------------------------------
                Dim mainWD As Integer = cellxy * PichX
                Dim mainHT As Integer = cellxy * PichY
                Dim gradWD As Integer = Ⅹ数値範囲Int(8, 1000, (CellsAllWD - mainWD) / 2)
                Dim gradHT As Integer = Ⅹ数値範囲Int(8, 1000, (CellsAllHT - mainHT) / 2)
                '-------------------------------------------------------------------------------
                Dim xxx0, xxx1, xxx2, xxx3, xxx4, xxx5, yyy0, yyy1, yyy2, yyy3, yyy4, yyy5 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 + 幅幅
                '-------------------------------------------------------------------------------
                If xxx4 - xxx3 < gradWD - 1 Then
                    'qqqqq("error ********** xxx4 - xxx3 < gradWD - 1")
                    Do While PichX > 1
                        PichX = PichX - 1
                        mainWD = cellxy * PichX
                        gradWD = Ⅹ数値範囲Int(8, 1000, (CellsAllWD - mainWD) / 2)
                        xxx0 = 0 : xxx1 = 幅幅 : xxx2 = xxx1 + gradWD : xxx3 = xxx2 + mainWD : xxx4 = mImgWD - 幅幅 : xxx5 = xxx4 + 幅幅
                        If xxx4 - xxx3 >= gradWD Then Exit Do
                    Loop
                End If
                If yyy4 - yyy3 < gradHT - 1 Then
                    'qqqqq("error ********** yyy4 - yyy3 < gradHT - 1")
                    Do While PichY > 1
                        PichY = PichY - 1
                        mainHT = cellxy * PichY
                        gradHT = Ⅹ数値範囲Int(8, 1000, (CellsAllHT - mainHT) / 2)
                        yyy0 = 0 : yyy1 = 幅幅 : yyy2 = yyy1 + gradHT : yyy3 = yyy2 + mainHT : yyy4 = mImgHT - 幅幅 : yyy5 = yyy4 + 幅幅
                        If yyy4 - yyy3 >= gradHT Then Exit Do
                    Loop
                End If
                CellPichX = PichX
                CellPichY = PichY
                '*******************************************************************************
                '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 = CboxMainPich234 * CboxMainPich234
                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 CboxMainPich234
                    Case 2 : idx = b + Basepich2
                    Case 3 : idx = b + Basepich3
                    Case 4 : idx = b + Basepich4
                End Select
                If (CboxMainPich234 = 2 And cColors(b + Basepich2 + 1) > 0) Or (CboxMainPich234 = 3 And cColors(b + Basepich3 + 1) > 0) Or (CboxMainPich234 = 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
                '2024/08/01 new ----------------------------------------------------------------
                Dim pich As Integer = CboxMainPich234
                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 \ pich
                    aax = dxnn * (a - (aa1 * pich))
                    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" & vbCrLf)
            ''***************************************************************
Goto_c原因再計算と中心部の描画は不要:
            '***************************************************************
            gggbol = zzグラデ領域描画すぐに(hDC, True)
            '***************************************************************
            Dim フォーカス枠現在の色 As Integer : Dim rctmp As RECT
            If Me.CboxEnabled Then フォーカス枠現在の色 = CboxOutSideLineColor 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, CboxCurColor, 色をぼかす)
            Next
            '***************************************************************
            If mDoneFirstShown Then
                If old_Enabled <> CboxEnabled Then
                    old_Enabled = CboxEnabled
                    RaiseEvent OnCboxEnabledChanged(CboxEnabled)
                End If
                If old_GradationBoxSize <> CboxGradationBoxSize Then
                    old_GradationBoxSize = CboxGradationBoxSize
                    RaiseEvent OnCboxGradationBoxSizeChanged(CboxGradationBoxSize)
                End If
                If old_GradationType <> CboxGradationType Then
                    old_GradationType = CboxGradationType
                    RaiseEvent OnCboxGradationTypeChanged(CboxGradationType)
                End If
                If old_MainPich234 <> CboxMainPich234 Then
                    old_MainPich234 = CboxMainPich234
                    RaiseEvent OnCboxMainPich234Changed(CboxMainPich234, CboxCurMainColor)
                End If
            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 = CboxCurMainColor()
        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) 'CboxCurMainColor
        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.CboxEnabled
        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.CboxEnabled)
        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
                'CboxCurMainColor 変更の描画
                'qqqqq("Goto_c原因再計算と中心部の描画は不要")
                Dim celxyxy, aaa, Divvv As Integer : Dim wグラデーション色配列(0) As Integer
                Dim nowCurMainColor As Integer = CboxCurMainColor
                'qqqqq("前　" + CStr(nowCurMainColor))
                celxyxy = CboxMainPich234 * CboxMainPich234 * CboxMainPich234
                Divvv = 2 * celxyxy / CboxGradationType
                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))
                '***************************************************************
                'CboxCurColorの描画()                                        
                Dim nn As Integer
                For nn = 5 To 6
                    gggbol = zzBtnDraw(hdc, Up状態, nn, CboxCurColor, 色をぼかす)
                Next
                For nn = 7 To 8
                    gggbol = ⅩRectDraw(hdc, mRects(nn), CboxCurColor, 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, CboxCurColor, (Me.CboxEnabled = 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 = CboxMainPich234 * CboxMainPich234
        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 * CboxMainPich234)
                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 \ CboxMainPich234
                wdgX = BoxNum * (a - (n * CboxMainPich234))
                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

End Class
