private string GetWordFromCharIndex(Point location, ref Point startWordLocation, ref Point endWordLocation) { string word = null; try { int mousePointerCharIndex = _rtb.GetCharIndexFromPosition(location); //int mousePointerLine = richText.GetLineFromCharIndex(mousePointerCharIndex); //int firstCharIndexInMousePointerLine = richText.GetFirstCharIndexFromLine(mousePointerLine); //int firstCharIndexInNextLine = richText.GetFirstCharIndexFromLine(mousePointerLine + 1); //if (firstCharIndexInNextLine < 0) //{ // firstCharIndexInNextLine = richText.Text.Length; //} //int hotTextStartIndex = richText.Find( // "http://1", firstCharIndexInMousePointerLine, firstCharIndexInNextLine, RichTextBoxFinds.NoHighlight); int startWord = mousePointerCharIndex; // Символы определения начала или окончания слова //char[] startOrEndWordChars = new char[] { ' ', '\n', '*', '(', ')', '.', ',', '"', '[',']','?','!','$','%','^' }; //bool cicle = false; while (startWord > 0) { startWord--; string s = _rtb.Text.Substring(startWord, 1); if (s.IndexOfAny(StartOrEndWordChars) >= 0) { startWord += 1; break; } } int endWord = mousePointerCharIndex; //bool cicle = false; while (endWord < _rtb.Text.Length) { string s = _rtb.Text.Substring(endWord, 1); if (s.IndexOfAny(StartOrEndWordChars) >= 0) { break; } endWord++; } word = _rtb.Text.Substring(startWord, endWord - startWord); while (word.EndsWith(".")) { word = word.Remove(word.Length - 1); endWord--; } startWordLocation = _rtb.GetPositionFromCharIndex(startWord); endWordLocation = _rtb.GetPositionFromCharIndex(endWord); } catch (Exception) { } return(word); }
/// <summary> /// Показать введенный текст поиска по подсказкам с клавиатуры /// </summary> private void ShowKeywordsHelp() { Point location = _richTextBoxCustom.GetPositionFromCharIndex(_richTextBoxCustom.SelectionStart > 0 ? _richTextBoxCustom.SelectionStart - 1 : 0); //int SplitterDistance = _splitContainerMain.SplitterDistance; //if (_splitContainerMain.Panel1Collapsed) // SplitterDistance = 0; KeywordsTT.Show( KeywordsTT.Tag.ToString(), //Подсказка по выбранному оператору this, new Point(dgvHelp.Location.X, dgvHelp.Location.Y - 20) ); DataView dv = ((DataTable)dgvHelp.DataSource).DefaultView; try { //if (dgvHelp.CurrentRow != null && // !string.IsNullOrEmpty(dgvHelp.CurrentRow.Cells["S_RootName"].Value.ToString())) //{ // int indexOfNameLike = FixedFilterSearchInHelpDGV.IndexOf(" OR (S_Name LIKE "); // if (indexOfNameLike > -1) // { // FixedFilterSearchInHelpDGV = FixedFilterSearchInHelpDGV.Substring(0, indexOfNameLike); // } //} try { //dv.RowFilter = string.Format("{0} AND {1} LIKE '%{2}%'", FixedFilterSearchInHelpDGV, TooltipDictionary.WORD, KeywordsTT.Tag); dv.RowFilter = string.Format("{0} LIKE '%{1}%' and ({2}=0 or {2}={3})", TooltipDictionary.WORD, KeywordsTT.Tag, TooltipDictionary.ID_CONTENT, (Application.OpenForms[0] as MainForm).GetCurrentQuestionId()); } catch (Exception ex) { KeywordsTT.Show(dv.RowFilter + Environment.NewLine + ex.Message, this); } SetColorAttributesHelpDGV(); } catch (InvalidOperationException) { } }