public static void Find1(string strRegex, bool isRegex, bool caseSensive, System.Windows.Forms.TextBox txtEdit, string ArticleName) { string ArticleText = txtEdit.Text; RegexOptions regOptions; if (caseSensive) regOptions = RegexOptions.None; else regOptions = RegexOptions.IgnoreCase; strRegex = Tools.ApplyKeyWords(ArticleName, strRegex); if (!isRegex) strRegex = Regex.Escape(strRegex); if (MatchObj == null || RegexObj == null) { int findStart = txtEdit.SelectionStart; RegexObj = new Regex(strRegex, regOptions); MatchObj = RegexObj.Match(ArticleText, findStart); txtEdit.SelectionStart = MatchObj.Index; txtEdit.SelectionLength = MatchObj.Length; txtEdit.Focus(); txtEdit.ScrollToCaret(); return; } else { if (MatchObj.NextMatch().Success) { MatchObj = MatchObj.NextMatch(); txtEdit.SelectionStart = MatchObj.Index; txtEdit.SelectionLength = MatchObj.Length; txtEdit.Focus(); txtEdit.ScrollToCaret(); } else { txtEdit.SelectionStart = 0; txtEdit.SelectionLength = 0; txtEdit.Focus(); txtEdit.ScrollToCaret(); ResetFind(); } } }
public static void SetEditBoxSelection(System.Windows.Forms.TextBox txtEdit, int inputIndex, int inputLength) { if (inputIndex > 0 && inputLength > 0 && (inputIndex + inputLength) < txtEdit.TextLength) { txtEdit.SelectionStart = inputIndex; txtEdit.SelectionLength = inputLength; } txtEdit.ScrollToCaret(); }
void AppendRichText(System.Windows.Forms.RichTextBox ctl, String str) { if (ctl.InvokeRequired) { this.Invoke(new Action<string>(ctl.AppendText), new object[] { str }); } else { ctl.AppendText(str); ctl.ScrollToCaret(); //Scrolls the contents of the control to the current caret position ctl.Refresh(); } }
/// <summary> /// Scrolls the given RTF box to the end. /// </summary> /// <param name="RichTextbox"></param> /// <remarks> /// The DLL call GetScrollRange returns only a 16 bit int - value maxes out at 65535. /// This causes the scrolling to stop. /// </remarks> public static void ScrollToEnd(System.Windows.Forms.RichTextBox RichTextbox) { #if false int min, max; GetScrollRange(RichTextbox.Handle, SB_VERT, out min, out max); SetScrollPos(RichTextbox.Handle, SB_VERT, max, 1); RichTextbox.SelectionStart = RichTextbox.Text.Length; //SendMessage(RichTextbox.Handle, EM_SETSCROLLPOS, 0, new POINT(0, max)); #else RichTextbox.SelectionStart = RichTextbox.Text.Length; RichTextbox.ScrollToCaret(); #endif }
public static void ScrollDown(System.Windows.Forms.RichTextBox box) { box.ScrollToCaret(); }