/// <summary> /// Edit keyword button clicked event handler. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event arguments.</param> private void buttonEdit_Click(object sender, System.EventArgs e) { // Get seloected keyword string keyword = this._richTextBox.Text.Substring(this._selectedKeywordStart, this._selectedKeywordLength); // Show keyword editor form KeywordEditor keywordEditor = new KeywordEditor( this.applicableKeywords, keyword, this._maxYValueIndex); if (keywordEditor.ShowDialog() == DialogResult.OK) { int start = this._selectedKeywordStart; int length = this._selectedKeywordLength; // Update currently selected kyword this._richTextBox.Text = this._richTextBox.Text.Substring(0, start) + keywordEditor.Keyword + this._richTextBox.Text.Substring(start + length); this._richTextBox.SelectionStart = start + keywordEditor.Keyword.Length; } // Set focus back to the editor this._richTextBox.Focus(); }
/// <summary> /// Insert keyword button clicked event handler. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event arguments.</param> private void buttonInsert_Click(object sender, System.EventArgs e) { // Show keyword editor form KeywordEditor keywordEditor = new KeywordEditor( this.applicableKeywords, string.Empty, this._maxYValueIndex); if (keywordEditor.ShowDialog() == DialogResult.OK) { if (_selectedKeywordLength > 0) { // Insert keyword at the end of curently selected keyword // and separate them with space this._richTextBox.SelectionStart = this._richTextBox.SelectionStart + this._richTextBox.SelectionLength; this._richTextBox.SelectionLength = 0; this._richTextBox.SelectedText = " " + keywordEditor.Keyword; } else { // Insert new keyword at current location this._richTextBox.SelectionLength = Math.Max(0, this._selectedKeywordLength); this._richTextBox.SelectedText = keywordEditor.Keyword; } } // Set focus back to the editor this._richTextBox.Focus(); }