Option Strict Off
Option Explicit On
Imports System.Windows.Forms
'------------------------------------ 2024/03/23 ------------------------------------
Public Class frmDlgStdBtnAllSet
#Region "宣言"
    Event aae基本ボタンを規定値に戻してください(ByVal BtnsKey As String)
    Event aae基本ボタン文字データーをください(ByVal BtnsKey As String, ByRef w文字データーすべて As String, ByRef wCutStr As String)
    Event aaeDlgWnd_ShowTrue_HideFalse(ByRef ShowTrue_HideFalse As Boolean)
    Event aaeDataGridCell_Changed(ByVal BtnsKey As String, ByVal rColumnIndex_0Base As Integer, ByVal rRowIndex_0Base As Integer)
    Event aaeボタンTextChanged(ByVal BtnsKey As String, ByVal rColumnIndex_0Base As Integer, ByVal rRowIndex_0Base As Integer, ByVal rNewText As String)
    Event aaeイベント_FormClosed_の最後に呼び出しています()
    Private mCurX As Integer = -1, mCurY As Integer = -1, mCurStr As String = ""
    Private mCurLabelColor As Color = Color.Yellow
    Private mABCD半角TextsDEF As String = ""
    Private mBCD全角TextsDEF As String = ""
    Private mひらかなTextsDEF As String = ""
    Private mカタカナTextsDEF As String = ""
    Private mCurModeKey As String = "", mOldModeKey As String = ""
#End Region

#Region "Form イベント"
    Friend Function Dlg_LoadShow0(ByVal rOwner As Form, ByVal cABCD半角 As String, ByVal cABCD全角 As String, ByVal cひらかな As String, ByVal cカタカナ As String, ByVal ABCD半角TextsDEF As String, ByVal ABCD全角TextsDEF As String, ByVal ひらかなTextsDEF As String, ByVal カタカナTextsDEF As String) As Boolean
        lblABCD半角.Text = cABCD半角 : lblABCD全角.Text = cABCD全角 : lblひらかな.Text = cひらかな : lblカタカナ.Text = cカタカナ
        mABCD半角TextsDEF = ABCD半角TextsDEF : mBCD全角TextsDEF = ABCD全角TextsDEF : mひらかなTextsDEF = ひらかなTextsDEF : mカタカナTextsDEF = カタカナTextsDEF
        DataGridView1.Visible = True
        DataGridView1.BackColor = Color.Coral
        Me.Icon = rOwner.Icon
        Me.Show(rOwner)
        If Not zzAppIniFileOp(0) Then gggint = ⅩFormMove(gcoフォームを親フォームの中心に移動, Me, , , , , , , , rOwner)
        RaiseEvent aaeDlgWnd_ShowTrue_HideFalse(True)
    End Function
    Private Sub frmDlgStdBtnAllSet_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        gggint = zzAppIniFileOp(1)  '必ず呼び出します。
        RaiseEvent aaeDlgWnd_ShowTrue_HideFalse(False)
    End Sub
    Private Sub frmDlgStdBtnAllSet_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        RaiseEvent aaeイベント_FormClosed_の最後に呼び出しています()
    End Sub
    Private Sub frmDlgStdBtnAllSet_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        qqqqq("frmDlgStdBtnAllSet_Disposed")
    End Sub
    '▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
    'フォームサイズと位置だけを保存する場合の、簡易_共通処理    '各フォームに記入する。
    Private Function zzAppIniFileOp(ByVal Load_0_QueryUnload_1_Resize_2_DoIniSave_3 As Long) As Boolean
        '読出し時に　INI ファイルが存在しない場合は　False　を返します。
        If gggAppIniFile Is Nothing Then Return False
        Return gggAppIniFile.aaAppIniFileOp_フォームサイズと位置だけ_共通処理(Load_0_QueryUnload_1_Resize_2_DoIniSave_3, Me, "固有の識別文")
    End Function
    '▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
#End Region

#Region "コントロール イベント"
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub
    Private Sub lblABCD半角_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblABCD半角.Click, lblABCD全角.Click, lblひらかな.Click, lblカタカナ.Click
        lblErrMsg.Visible = False
        If Not (TypeOf sender Is Label) Then Return
        '-----------------------------------------------------------------------------------------
        Dim lbl As Label = sender
        Dim c2 As Color = Color.LightGray
        If lbl Is lblABCD半角 Then lblABCD半角.BackColor = mCurLabelColor Else lblABCD半角.BackColor = c2
        If lbl Is lblABCD全角 Then lblABCD全角.BackColor = mCurLabelColor Else lblABCD全角.BackColor = c2
        If lbl Is lblひらかな Then lblひらかな.BackColor = mCurLabelColor Else lblひらかな.BackColor = c2
        If lbl Is lblカタカナ Then lblカタカナ.BackColor = mCurLabelColor Else lblカタカナ.BackColor = c2
        '-----------------------------------------------------------------------------------------
        mOldModeKey = mCurModeKey : mCurModeKey = lbl.Text
        Dim wCutStr As String = "" : Dim w文字データーすべて As String = ""
        RaiseEvent aae基本ボタン文字データーをください(mCurModeKey, w文字データーすべて, wCutStr)
        Try
            If wCutStr <> "" Then
                Dim wAry() As String = {""}
                Dim m As Integer = Ⅹ文をカットして配列にする(w文字データーすべて, wCutStr, wAry)
                If m = 100 Then
                    DataGridView1.Rows.Clear()
                    Dim sss(9) As String
                    Dim a, c, n, r As Integer
                    For c = 0 To 9
                        For a = 0 To 9
                            n = c * 10 + a + 1
                            sss(a) = wAry(n)
                        Next
                        r = DataGridView1.Rows.Add(sss)
                        DataGridView1.Rows(r).HeaderCell.Value = CStr(c + 1)
                    Next
                    DataGridView1.Item(9, 9).ReadOnly = True
                End If
                mCurX = 0 : mCurY = 0
                RaiseEvent aaeDataGridCell_Changed(mCurModeKey, 0, 0)
                Call zzbtnSetDEF_SetEnabled()
                mOldModeKey = mCurModeKey
                DataGridView1.Item(0, 0).Selected = True
            End If
        Catch ex As Exception
        End Try
    End Sub
    Private Sub btnSetDEF_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSetDEF.Click
        lblErrMsg.Visible = False
        If DataGridView1.Rows.Count <> 10 Then Return
        Dim s As String = ""
        Select Case mCurModeKey
            Case lblABCD半角.Text : s = mABCD半角TextsDEF
            Case lblABCD全角.Text : s = mBCD全角TextsDEF
            Case lblひらかな.Text : s = mひらかなTextsDEF
            Case lblカタカナ.Text : s = mカタカナTextsDEF
        End Select
        If s = "" Then Return
        If 2 = MsgBox("現在表示されている基本ボタンの文字すべてを、" & vbCrLf & vbCrLf & "このアプリの規定値に戻します。" & vbCrLf & vbCrLf & "やり直しはできません。" & vbCrLf & vbCrLf & "よろしいですか？", 33, "基本ボタンの文字すべてを規定値に戻す") Then
            'Ret = 1 '< 了解 >  'Ret = 2 '< 取消 >
            Return
        End If
        With DataGridView1
            Dim x, y As Integer, a As Integer = 0 : Dim cell As DataGridViewCell
            For y = 0 To .Rows.Count - 1
                For x = 0 To .Columns.Count - 1
                    cell = DataGridView1.Item(x, y)
                    a += 1
                    cell.Value = Mid(s, a, 1)
                Next
            Next
        End With
        btnSetDEF.Enabled = False
        RaiseEvent aae基本ボタンを規定値に戻してください(mCurModeKey)
    End Sub
    Private Sub lblErrMsg_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblErrMsg.Click
        lblErrMsg.Visible = False
    End Sub
#End Region

#Region "DataGridView1 イベント"
    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim ColIndex As Integer = e.ColumnIndex, RowIndex As Integer = e.RowIndex
        Try
            lblErrMsg.Visible = False
            If (ColIndex = 9 And RowIndex = 9) Then
                lblErrMsg.Visible = True
                If mCurX < 0 Or mCurY < 0 Then Return
                DataGridView1.Item(mCurX, mCurY).Selected = True
                Return 'Ret Key 変更禁止
            End If
            mCurX = ColIndex
            mCurY = RowIndex
            If mCurX < 0 Or mCurY < 0 Then Return
            Dim c As DataGridViewCell = DataGridView1.Item(mCurX, mCurY)
            If TypeOf c.Value Is String Then
                Dim s As String = c.Value
                If mCurStr <> s Then
                    mCurStr = s
                    Dim key As String = CurKey()
                    RaiseEvent aaeDataGridCell_Changed(key, mCurX, mCurY)
                End If
            End If
        Catch ex As Exception
        End Try
    End Sub
    Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
        'qqqqq("DataGridView1_CellEndEdit")
        Try
            Dim key As String = CurKey()
            If mOldModeKey <> key Then
                Return
            End If
            Dim sss As String = DataGridView1.Item(e.ColumnIndex, e.RowIndex).FormattedValue
            If mCurStr <> sss Then
                qqqqq(mCurStr & " ---> " & sss)
                RaiseEvent aaeボタンTextChanged(key, e.ColumnIndex, e.RowIndex, sss)
                Call zzbtnSetDEF_SetEnabled()
            End If
        Catch ex As Exception
            MsgBox("ERROR in DataGridView1_CellEndEdit()" & ex.ToString)
        End Try
    End Sub
#End Region

#Region "内部ヘルパー関数"
    Private Sub zzbtnSetDEF_SetEnabled()
        Try
            Dim s As New String(" ", 100), t As String = "", c As DataGridViewCell
            With DataGridView1
                Dim x, y As Integer, a As Integer = 0
                For y = 0 To .Rows.Count - 1
                    For x = 0 To .Columns.Count - 1
                        c = DataGridView1.Item(x, y)
                        If TypeOf c.Value Is String Then
                            t = c.Value
                            a += 1
                            Mid(s, a, 1) = Mid(t, 1, 1)
                        End If
                    Next
                Next
            End With
            Select Case mCurModeKey 'CurKey()
                Case lblABCD半角.Text : btnSetDEF.Enabled = (s <> mABCD半角TextsDEF)
                Case lblABCD全角.Text : btnSetDEF.Enabled = (s <> mBCD全角TextsDEF)
                Case lblひらかな.Text : btnSetDEF.Enabled = (s <> mひらかなTextsDEF)
                Case lblカタカナ.Text : btnSetDEF.Enabled = (s <> mカタカナTextsDEF)
            End Select
        Catch ex As Exception
        End Try
    End Sub
#End Region

#Region "外部インターフェイス"
    Friend Function CurKey() As String
        If lblABCD半角.BackColor = mCurLabelColor Then Return lblABCD半角.Text
        If lblABCD全角.BackColor = mCurLabelColor Then Return lblABCD全角.Text
        If lblひらかな.BackColor = mCurLabelColor Then Return lblひらかな.Text
        If lblカタカナ.BackColor = mCurLabelColor Then Return lblカタカナ.Text
        Return ""
    End Function
    Friend Function CurCellIndex_Column_Row_Base0(ByRef wColumnIndex_Base0 As Integer, ByRef wRowIndex_Base0 As Integer) As Boolean
        Dim cell As DataGridViewCell
        With DataGridView1
            Dim x, y As Integer
            For x = 0 To .Columns.Count - 1
                For y = 0 To .Rows.Count - 1
                    cell = DataGridView1(x, y)
                    If cell.Selected Then
                        wColumnIndex_Base0 = x : wRowIndex_Base0 = y
                        Return True
                    End If
                Next
            Next
        End With
        Return False
    End Function
#End Region


End Class