代码有点多,分两次发给你,前不久写的带查找关键字高亮,希望对你有所帮助:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SLsoft;
using System.Text.RegularExpressions;
namespace TxtEdit
{
public partial class SelOrRep : Form
{
#region 全局变量
Edit edit = new Edit();
int index = -1; //当前选中文本索引
bool matched = false; //是否匹配
bool highLight = false; //是否全部高亮
#endregion
public SelOrRep(int index)
{
InitializeComponent();
tabControl.SelectedTab = tabControl.TabPages[index];
if (tabControl.SelectedIndex == 0)
{
this.txb_sel.Focus();
}
else
{
this.txb_selTxt.Focus();
}
this.TopMost = true;
edit = (Edit)this.Owner;
}
private void btn_exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void SelOrRep_FormClosing(object sender, FormClosingEventArgs e)
{
ReSelect();
edit = (Edit)this.Owner;
if (highLight)
{
btn_light.Text = "全部高亮";
btn_light_Click(sender, new EventArgs());
}
edit.array.Remove(this.Name);
}