/// <summary> /// Insert text. /// </summary> /// <param name="text">Text to insert</param> /// <param name="replaceSelection">Determines if selected text should be replaced or not</param> /// <param name="insertAtRight">If true and replaceSelection is false, the inserted text will be inserted at the right /// boundary of the selection instead of the left boundary.</param> protected void insertText(string text, bool replaceSelection, bool insertAtRight) { int selLen = m_textbox.SelectionLength; int selStart = m_textbox.SelectionStart; int newSelStart = selStart + text.Length; int newSelLength = 0; if (replaceSelection) { if (selLen > 0) { m_textbox.Text = m_textbox.Text.Remove(selStart, selLen); } m_textbox.Text = m_textbox.Text.Insert(selStart, text); } else { if (insertAtRight) { m_textbox.Text = m_textbox.Text.Insert(selStart + selLen, text); selStart += selLen; } else { m_textbox.Text = m_textbox.Text.Insert(selStart, text); m_textbox.Select(selStart + text.Length, 0); } } m_textbox.Focus(); // Do select AFTER focus, otherwise, focus changes selection to whole box. m_textbox.Select(newSelStart, newSelLength); m_textbox.Refresh(); }
/// <summary> /// Convert double dashes to single dash /// XML considers -- to be part of a comment or some such and thus causes a crash /// This is a hack to merely convert -- to - (it's exceedingly unlikely a user will really want two dashes in a row) /// </summary> private void RemoveExtraDashes() { string s = m_wordformTextBox.Text; int i = s.IndexOf("--"); while (i > -1) { m_wordformTextBox.Text = s.Replace("--", "-"); m_wordformTextBox.Refresh(); s = m_wordformTextBox.Text; i = s.IndexOf("--"); } }
/// <summary> /// Insert text. /// </summary> /// <param name="text">Text to insert</param> /// <param name="replaceSelection">Determines if selected text should be replaced or not</param> /// <param name="insertAtRight">If true and replaceSelection is false, the inserted text will be inserted at the right /// boundary of the selection instead of the left boundary.</param> protected void InsertText(string text, bool replaceSelection, bool insertAtRight) { int selLen = m_textbox.SelectionLength; int selStart = m_textbox.SelectionStart; int newSelStart = selStart + text.Length; const int newSelLength = 0; var bldr = m_textbox.Tss.GetBldr(); if (replaceSelection) { if (selLen > 0) { m_textbox.Text = m_textbox.Text.Remove(selStart, selLen); } bldr.Replace(selStart, selStart, text, null); m_textbox.Tss = bldr.GetString(); } else { if (insertAtRight) { bldr.Replace(selStart + selLen, selStart + selLen, text, null); m_textbox.Tss = bldr.GetString(); } else { bldr.Replace(selStart, selStart, text, null); m_textbox.Tss = bldr.GetString(); m_textbox.Select(selStart + text.Length, 0); } } m_textbox.Focus(); // Do select AFTER focus, otherwise, focus changes selection to whole box. m_textbox.Select(newSelStart, newSelLength); m_textbox.Refresh(); }