コード例 #1
0
 private void BtnSearchClear_Click(object sender, EventArgs e)
 {
     CmbSearch.Text = "";
     RtbResult.Text = GblResult_AryText[GblResult_AryIndex].ToString();
     Text           = ProgramID;
     _ = CmbSearch.Focus();
 }
コード例 #2
0
        private void BtnSearch_Click(object sender, EventArgs e)
        {
            if (CmbSearch.Text.Length == 0)
            {
                BtnSearchClear_Click(sender, e);
                return;
            }

            // 検索履歴から重複排除
            _ = CmbSearch.Items.Add(CmbSearch.Text);
            List <string> l1 = new List <string>();

            foreach (string _s1 in CmbSearch.Items)
            {
                l1.Add(_s1);
            }
            l1.Sort();
            CmbSearch.Items.Clear();

            string sOld = "";

            foreach (string _s1 in l1)
            {
                if (sOld != _s1)
                {
                    _    = CmbSearch.Items.Add(_s1);
                    sOld = _s1;
                }
            }
            l1.Clear();

            int iLineBgnPos = 0;

            // 画面を初期化
            RtbResult.Text = GblResult_AryText[GblResult_AryIndex].ToString();

            // 行毎に検索!!
            // 検索位置を着色
            foreach (string _s1 in RtbResult.Text.Split('\n'))
            {
                foreach (Match _m1 in Regex.Matches(_s1, CmbSearch.Text, RegexOptions.IgnoreCase))
                {
                    RtbResult.Select(iLineBgnPos + _m1.Index, _m1.Value.Length);
                    RtbResult.SelectionColor     = Color.White;
                    RtbResult.SelectionBackColor = Color.Red;
                }
                iLineBgnPos += _s1.Length + 1;
            }

            // 最初の検索位置へスクロール
            RtbResult.SelectionStart = Regex.Match(RtbResult.Text, CmbSearch.Text, RegexOptions.IgnoreCase).Index;
            RtbResult.ScrollToCaret();

            _ = CmbSearch.Focus();
        }
コード例 #3
0
        private bool IsValidateSearchKey(ref string searchKey)
        {
            if (string.IsNullOrWhiteSpace(searchKey))
            {
                if (string.IsNullOrWhiteSpace(_lastSearchKey))
                {
                    return(false);
                }

                searchKey = _lastSearchKey;
                CmbSearch.Focus();
                CmbSearch.Text = _lastSearchKey;
            }
            else
            {
                _lastSearchKey = searchKey;
            }
            return(true);
        }
コード例 #4
0
        private void BtnSearchNext_Click(object sender, EventArgs e)
        {
            if (CmbSearch.Text.Length == 0)
            {
                _ = CmbSearch.Focus();
                return;
            }

            _ = RtbResult.Focus();
            CmbSearch.SelectionStart = 0;

            // 行毎に検索!!
            // 検索位置にカーソル移動
            while (Regex.IsMatch(RtbResult.Text, CmbSearch.Text, RegexOptions.IgnoreCase))
            {
                int iLineBgnPos = 0;

                foreach (string _s1 in RtbResult.Text.Split('\n'))
                {
                    // 無駄なループを減らすため、こまめに GblResult_CursorPos の位置をチェック
                    if (iLineBgnPos + _s1.Length > GblResult_CursorPos)
                    {
                        foreach (Match _m1 in Regex.Matches(_s1, CmbSearch.Text, RegexOptions.IgnoreCase))
                        {
                            if (iLineBgnPos + _m1.Index >= GblResult_CursorPos)
                            {
                                _ = RtbResult.Focus();
                                RtbResult.Select(iLineBgnPos + _m1.Index, _m1.Value.Length);
                                GblResult_CursorPos = iLineBgnPos + _m1.Index + _m1.Value.Length;
                                return;
                            }
                        }
                    }
                    iLineBgnPos += _s1.Length + 1;
                }

                GblResult_CursorPos = 0;
            }
        }
コード例 #5
0
        private void RtbResult_KeyUp(object sender, KeyEventArgs e)
        {
            // RichTextBox で以下の動作は不安定
            //   [Ctrl]+[↑]
            //   [Ctrl]+[↓]

            // [Ctrl]+[PgUp]
            if (e.KeyData == (Keys.Control | Keys.PageUp))
            {
                RtbResult.Select(0, 0);
                RtbResult.ScrollToCaret();
                return;
            }

            // [Ctrl]+[PgDn]
            if (e.KeyData == (Keys.Control | Keys.PageDown))
            {
                RtbResult.Select(RtbResult.TextLength, 0);
                RtbResult.ScrollToCaret();
                return;
            }

            switch (e.KeyCode)
            {
            case (Keys.Escape):
                CmbSearch.Focus();
                break;

            case (Keys.F3):
                BtnSearchNext_Click(sender, null);
                break;

            default:
                GblResult_CursorPos = RtbResult.SelectionStart;
                break;
            }
        }
コード例 #6
0
 private void CmsSearch_Opened(object sender, EventArgs e)
 {
     _ = CmbSearch.Focus();
 }