Option Strict Off
Option Explicit On
Imports System.Windows.Forms
'------------------------------------ 2024/03/23 ------------------------------------
Public Class frmDlgUserBtnAllSet

#Region "宣言"
    Event aaeDlgWnd_ShowTrue_HideFalse(ByRef ShowTrue_HideFalse As Boolean)
    Event aaeDataGridCell_Changed(ByVal rColumnIndex_0Base As Integer, ByVal rRowIndex_0Base As Integer, ByVal 改行付き文 As String)
    Event aaeボタンTextChanged(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 = ""
#End Region

#Region "Form イベント"
    Friend Function Dlg_LoadShow0(ByVal rOwner As Form, ByVal txtCurCell_MaxLen As Integer, ByVal Texts As String, ByVal Cut As String) As Boolean
        DataGridView1.Visible = True
        DataGridView1.BackColor = Color.Coral
        Dim wAry() As String = {""}
        Dim m As Integer = Ⅹ文をカットして配列にする(Texts, Cut, wAry)
        Dim sss(9) As String
        Dim a, c, n, r As Integer
        For c = 0 To 19
            For a = 0 To 9
                n = c * 10 + a + 1
                If n > m Then GoTo LOOPOFF
                sss(a) = wAry(n)
            Next
            r = DataGridView1.Rows.Add(sss)
            DataGridView1.Rows(r).HeaderCell.Value = CStr(c + 1)
        Next
LOOPOFF:
        DataGridView1.Item(1, 0).ReadOnly = True
        DataGridView1.Item(9, 9).ReadOnly = True
        DataGridView1.Item(9, 19).ReadOnly = True
        txtCurCell.MaxLength = txtCurCell_MaxLen
        Me.btn変更する.Enabled = False
        Me.Icon = rOwner.Icon
        Me.Show(rOwner)
        If Not zzAppIniFileOp(0) Then gggint = ⅩFormMove(gcoフォームを親フォームの中心に移動, Me, , , , , , , , rOwner)
        RaiseEvent aaeDlgWnd_ShowTrue_HideFalse(True)
        mCurX = 1 : mCurY = 0
        Call zzDataGridView1_CellClick(1, 0)
    End Function
    Private Sub frmDlgUserBtnAllSet_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 frmDlgUserBtnAllSet_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        RaiseEvent aaeイベント_FormClosed_の最後に呼び出しています()
    End Sub
    Private Sub frmDlgUserBtnAllSet_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        qqqqq("frmDlgUserBtnAllSet_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 btn変更する_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn変更する.Click
        lblErrMsg.Visible = False
        If mCurX < 0 Or mCurY < 0 Then Return
        Dim sss As String = txtCurCell.Text
        mCurStr = sss
        Dim チルダ付文 As String = Appf改行コード変換文(0, sss)
        DataGridView1.Item(mCurX, mCurY).Value = チルダ付文
        RaiseEvent aaeボタンTextChanged(mCurX, mCurY, チルダ付文)
        btn変更する.Enabled = (mCurStr <> txtCurCell.Text)
    End Sub
    Private Sub txtCurCell_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCurCell.TextChanged
        If mCurX = 9 And mCurY = 9 Or mCurX = 9 And mCurY = 19 Then
            txtCurCell.Text = ""
            btn変更する.Enabled = False
        End If
        btn変更する.Enabled = (mCurStr <> txtCurCell.Text)
    End Sub
    Private Sub txtCurCell_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCurCell.Click
        lblErrMsg.Visible = False : txtCurCell.Enabled = True
    End Sub
    Private Sub lblErrMsg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblErrMsg.Click
        lblErrMsg.Visible = False : txtCurCell.Enabled = True
    End Sub
#End Region

#Region "DataGridView1 イベント"
    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Call zzDataGridView1_CellClick(e.ColumnIndex, e.RowIndex)
    End Sub
#End Region

#Region "内部　ヘルパー"
    Private Sub zzDataGridView1_CellClick(ByVal ColX As Integer, ByVal RowY As Integer)
        Try
            lblErrMsg.Visible = False
            If (ColX = 0 And RowY = 0) Or (ColX = 9 And RowY = 9) Or (ColX = 9 And RowY = 19) Then
                lblErrMsg.Visible = True
                txtCurCell.Text = ""
                txtCurCell.Enabled = False
                If mCurX < 0 Or mCurY < 0 Then
                    Return
                Else
                    DataGridView1.Item(mCurX, mCurY).Selected = True
                End If
            Else
                mCurX = ColX : mCurY = RowY
            End If
            If mCurX < 0 Or mCurY < 0 Then
                Return
            Else
                DataGridView1.Item(mCurX, mCurY).Selected = True
                Dim c As DataGridViewCell = DataGridView1.Item(mCurX, mCurY)
                If TypeOf c.Value Is String Then
                    mCurStr = c.Value
                    Dim 改行付き文 As String = Appf改行コード変換文(1, mCurStr)
                    txtCurCell.Text = 改行付き文
                    btn変更する.Enabled = False
                    If lblErrMsg.Visible = False Then txtCurCell.Enabled = True
                    RaiseEvent aaeDataGridCell_Changed(mCurX, mCurY, 改行付き文)
                End If
            End If
        Catch ex As Exception
        End Try
    End Sub
#End Region

#Region "外部インターフェイス"
    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


