Option Strict Off
Option Explicit On
Imports System.Windows.Forms
'------------------------------------ 2024/03/23 ------------------------------------
Public Class frmDlgJishoEdit
#Region "愰尵"
    Private wUsersRetList As ListBox = Nothing
    Private mChanged As Boolean = False
#End Region

#Region "Form 僀儀儞僩"
    Friend Function frmDlgJishoEdit_LoadShow1(ByVal rOwner As Form, ByVal ary() As String, ByVal rFontColorData As ListBox, ByVal rJiKeyLblBox As Label, ByRef wRetList As ListBox) As Boolean
        Try
            wUsersRetList = wRetList
            With rJiKeyLblBox : Me.aaoKeyLbl.BackColor = .BackColor : Me.aaoKeyLbl.ForeColor = .ForeColor : Me.aaoKeyLbl.Text = .Text : End With
            gggbol = 嘳ObjColorFontCopy(rFontColorData, mJiList)
            mJiList.ColumnWidth = 嘳悢抣斖埻Int(150, 300, (rFontColorData.ColumnWidth))
            gggint = 嘳儕僗僩儃僢僋僗偵_暥攝楍偐傜儕僗僩傪擖傟傞(mJiList, ary, True, 2)
            mJiList.Items.Add("*")
            gggint = 嘳儕僗僩儃僢僋僗偺慡儕僗僩傪_暿偺儕僗僩儃僢僋僗偵僐僺乕(aaoJiListBK, mJiList) : aaoJiListBK.Visible = False
            Me.mJiEditText.Parent = mJiList
            Dim bk As Color = Me.BackColor : Dim fr As Color = Me.ForeColor
            Me.mJiEditBtnADD.Parent = mJiList : mJiEditBtnADD.BackColor = bk : mJiEditBtnADD.ForeColor = fr
            Me.mJiEditBtnDEL.Parent = mJiList : mJiEditBtnDEL.BackColor = bk : mJiEditBtnDEL.ForeColor = fr
            Me.mJiEditBtnCAN.Parent = mJiList : mJiEditBtnCAN.BackColor = bk : mJiEditBtnCAN.ForeColor = fr
            Me.btn揔梡.Enabled = False
            Me.Icon = rOwner.Icon
            If Not zzAppIniFileOp(0) Then gggint = 嘳FormMove(gco僼僅乕儉傪恊僼僅乕儉偺拞怱偵堏摦, Me, , , , , , , , rOwner)
            Me.ShowDialog(rOwner)
            '--------------------------------------------------------------------------------
            Return mChanged
        Catch ex As Exception
        End Try
    End Function
    Private Sub frmDlgJishoEdit_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Call frmDlgJishoEdit_ResizeEnd(Nothing, Nothing)
    End Sub
    Private Sub frmDlgJishoEdit_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ResizeEnd
        With mJiList
            Dim xy As Integer = .Left
            .SetBounds(0, 0, Me.ClientRectangle.Width - xy - xy, Me.ClientRectangle.Height - xy - .Top, BoundsSpecified.Size)
        End With
        If mJiEditText.Visible Then Call mJiEditBtnCAN_Click(Nothing, Nothing)
    End Sub
    Private Sub frmDlgJishoEdit_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        gggint = zzAppIniFileOp(1)  '昁偢屇傃弌偟傑偡丅
    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 mJiList_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mJiList.Click
        Dim n As Integer = mJiList.SelectedIndex
        If n >= 0 Then
            Try
                If mJiEditText.Visible Then
                    Call zmJiEditText_OnOff(False)
                    mJiList.Refresh()
                    'qqqqq("mJiEditText.Visible")
                End If
                Dim rcgl As Rectangle = mJiList.GetItemRectangle(n)
                With mJiEditText
                    .BorderStyle = BorderStyle.FixedSingle
                    .SetBounds(rcgl.Left - 1, rcgl.Top, rcgl.Width + 1, rcgl.Height, BoundsSpecified.All)
                    .Visible = True
                    .BringToFront()
                    Dim s As String = Trim(aagg儕僗僩儃僢僋僗偺僥僉僗僩(mJiList, n))
                    If s <> "*" Then .Text = s Else .Text = ""
                    mJiEditText.Focus()
                End With
                Call zmJiEditText_OnOff(True)
            Catch ex As Exception
            End Try
            'qqqqq("zmJiList_MouseUp_EditShow")
        End If
    End Sub
    Private Sub btn揔梡_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn揔梡.Click
        mChanged = Not 嘳儕僗僩儃僢僋僗偺慡儕僗僩偺斾妑(aaoJiListBK, mJiList, False, False)
        If mChanged And (wUsersRetList IsNot Nothing) Then
            mJiList.Items.RemoveAt(mJiList.Items.Count - 1)
            Dim max As Integer = 嘳儕僗僩儃僢僋僗偺慡儕僗僩傪_暿偺儕僗僩儃僢僋僗偵僐僺乕(wUsersRetList, mJiList)
        End If
        Me.Close()
    End Sub
    Private Sub btn僉儍儞僙儖_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn僉儍儞僙儖.Click
        mChanged = False
        Me.Close()
    End Sub
#End Region

#Region "僐儞僩儘乕儖 僀儀儞僩丂僠僢僾僥僉僗僩"
    Private Sub mJiEditBtnADD_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mJiEditBtnADD.Click
        Call mJiEditbtns_Click_COM(0)
        btn揔梡.Enabled = Not 嘳儕僗僩儃僢僋僗偺慡儕僗僩偺斾妑(aaoJiListBK, mJiList, False, False)
    End Sub
    Private Sub mJiEditBtnDEL_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mJiEditBtnDEL.Click
        Call mJiEditbtns_Click_COM(1)
        btn揔梡.Enabled = Not 嘳儕僗僩儃僢僋僗偺慡儕僗僩偺斾妑(aaoJiListBK, mJiList, False, False)
    End Sub
    Private Sub mJiEditBtnCAN_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mJiEditBtnCAN.Click
        Call mJiEditbtns_Click_COM(2)
    End Sub
    Private Function mJiEditbtns_Click_COM(ByVal Index As Integer) As Boolean
        On Error GoTo errop
        Dim a As Integer : Dim eAdd, eDel As Boolean : Dim w, h, s As String
        Select Case Index
            Case 0, 1 '捛壛 / 嶍彍
                Call zKbxTipTxtTextCheck(eAdd, eDel)
                If (Index = 0 And eAdd = False) Or (Index = 1 And eDel = False) Then GoTo errop1
                Select Case Index
                    Case 0
                        s = Mid(mJiEditText.Text, 1, 100)
                        s = 嘳StrChgOldStrNewStr(s, vbCrLf, "~")
                        s = 嘳StrChgOldStrNewStr(s, ",", "丄")
                        mJiList.Items.Insert(mJiList.SelectedIndex, s) 'add
                    Case 1
                        mJiList.Items.RemoveAt(mJiList.SelectedIndex) 'del
                End Select
                mJiList.Refresh()
            Case 2 '庢徚
                'nop
        End Select
        Call zmJiEditText_OnOff(False)
        Return True
errop1:
        Call AppfMyBeep()
        Return False
errop:
        If Err.Number Then MsgBox("""mJiEditbtns_Click_COM"" 偱僄儔乕" & vbCrLf & Err.Description)
        Return False
    End Function
    Private Sub mJiEditText_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles mJiEditText.TextChanged
        Dim eAdd, eDel As Boolean
        If mJiEditText.Visible Then
            Call zKbxTipTxtTextCheck(eAdd, eDel)
            mJiEditBtnADD.Enabled = eAdd
            mJiEditBtnDEL.Enabled = eDel
            If mJiEditText.ImeMode <> Windows.Forms.ImeMode.Off Then
                If mJiEditBtnADD.Enabled Then mJiEditBtnADD.Focus()
            End If
        End If
    End Sub
#End Region

#Region "撪晹僿儖僷乕娭悢"
    Private Function zKbxTipTxtTextCheck(ByRef eAdd As Boolean, ByRef eDel As Boolean) As Boolean
        Dim s As String
        s = Trim(mJiEditText.Text)
        If s = "" Or s = "*" Or InStr(s, "*") > 0 Then  ' Or InStr(s, c44) > 0 Then
            eAdd = False
            eDel = False
        Else
            If mJiList.FindStringExact(s) = ListBox.NoMatches Then eAdd = True Else eAdd = False
            If s = aagg儕僗僩儃僢僋僗偺僥僉僗僩(mJiList, mJiList.SelectedIndex) Then eDel = True Else eDel = False
        End If
        Return True
    End Function
    Private Function zmJiEditText_OnOff(ByRef mJiEditTextVisible As Boolean) As Boolean
        Dim x, y, w, h, w3 As Integer
        mJiEditText.Visible = mJiEditTextVisible
        If mJiEditTextVisible Then
            With mJiEditText
                .Font = mJiList.Font
                x = .Left
                y = .Bottom
                w = .Width \ 3
                h = .Height + 5
                w3 = .Width - w - w
                If y + h > mJiList.ClientRectangle.Height Then
                    y = .Top - h
                End If
            End With
            mJiEditBtnADD.SetBounds(x, y, w, h, BoundsSpecified.All)
            mJiEditBtnDEL.SetBounds(x + w, y, w, h, BoundsSpecified.All)
            mJiEditBtnCAN.SetBounds(x + w + w, y, w3, h, BoundsSpecified.All)
            Call mJiEditText_TextChanged(Nothing, Nothing)
        Else
            mJiEditText.Top = -100
            mJiEditBtnADD.Top = -100
            mJiEditBtnDEL.Top = -100
            mJiEditBtnCAN.Top = -100
        End If
        mJiEditText.Visible = mJiEditTextVisible
        mJiEditBtnADD.Visible = mJiEditTextVisible
        mJiEditBtnDEL.Visible = mJiEditTextVisible
        mJiEditBtnCAN.Visible = mJiEditTextVisible
    End Function
#End Region

End Class
