Beispiel #1
0
 private void OnTargetFound(TargetFoundEventArgs args)
 {
     if (m_TargetFoundEvent != null)
     {
         m_TargetFoundEvent(this, args);
     }
 }
Beispiel #2
0
        /// <summary>
        /// 找下一個符合的字串。
        /// </summary>
        /// <returns></returns>
        public bool FindNext()
        {
            string target = txtTarget.Text;

            DecideStartPositionEventArgs dspArgs = new DecideStartPositionEventArgs();

            OnDecidingStartPosition(dspArgs);

            int lineIdx = dspArgs.LineIndex;                    // m_StartLineIndex;
            int wordIdx = dspArgs.WordIndex;                    // m_StartWordIndex;

            int         i;
            BrailleLine brLine;

            if (lineIdx >= m_BrDoc.LineCount)
            {
                return(false);
            }

            brLine = m_BrDoc[lineIdx];

            if (!this.IsFirstTime)
            {
                wordIdx++;                      // 若是找下一筆,則從目前位置的下一個字開始找起.
                if (wordIdx >= brLine.WordCount)
                {
                    lineIdx++;
                    if (lineIdx >= m_BrDoc.LineCount)
                    {
                        return(false);
                    }
                    wordIdx = 0;
                }
            }

            while (true)
            {
                if (m_CaseSensitive)
                {
                    i = brLine.IndexOf(target, wordIdx, StringComparison.Ordinal);
                }
                else
                {
                    i = brLine.IndexOf(target, wordIdx, StringComparison.OrdinalIgnoreCase);
                }

                if (i >= 0 && i >= wordIdx)                     // 有找到?
                {
                    m_FoundLineIndex = lineIdx;
                    m_FoundWordIndex = i;

                    // 觸發事件。
                    TargetFoundEventArgs args = new TargetFoundEventArgs(m_FoundLineIndex, m_FoundWordIndex);
                    OnTargetFound(args);

                    // 調整起始搜尋的位置(移至下一個字),以便下次搜尋下一筆。
                    m_StartLineIndex = m_FoundLineIndex;
                    m_StartWordIndex = m_FoundWordIndex;
                    IsFirstTime      = false;
                    return(true);
                }

                // 沒找到,往下一個字移動.

                wordIdx++;
                if (wordIdx + target.Length >= brLine.WordCount)
                {
                    lineIdx++;
                    if (lineIdx >= m_BrDoc.LineCount)
                    {
                        break;
                    }
                    brLine  = m_BrDoc[lineIdx];
                    wordIdx = 0;
                }
            }
            return(false);
        }