private void btnReplaceAll_Click(object sender, EventArgs e) { ContentSearchReplacer sr = CreateSearchReplacer(); if (sr != null) { int index = sr.ReplaceAll(this._CommandArgs); if (index < 0) { MessageBox.Show( this, WriterStrings.CannotSearchSpecifyContent, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show( this, string.Format(WriterStrings.PromptReplaceAllResult_Times, index), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
/// <summary> /// 创建查找替换文本内容的操作对象 /// </summary> /// <returns>创建的操作对象</returns> private ContentSearchReplacer CreateSearchReplacer() { UpdateCommandArgs(); DomDocument document = this.TextDocument; if (document == null && this.WriterControl != null) { document = this.WriterControl.Document; } if (document == null) { return(null); } ContentSearchReplacer sr = new ContentSearchReplacer(); sr.Document = document; return(sr); }
/// <summary> /// 替换按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnReplace_Click(object sender, EventArgs e) { ContentSearchReplacer sr = CreateSearchReplacer(); if (sr != null) { int index = sr.Replace(this._CommandArgs); if (index < 0) { MessageBox.Show( this, WriterStrings.CannotSearchSpecifyContent, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (this.WriterControl != null) { //this.WriterControl.Focus(); } } }