C#如何编程查找函数
我有一个C#程序,它使用了find函数,但是它能够找到单词,但不会在richTextBox中突出显示找到的单词 有人能告诉我密码吗 谢谢 查找函数类窗体:C#如何编程查找函数,c#,textbox,find,highlighting,C#,Textbox,Find,Highlighting,我有一个C#程序,它使用了find函数,但是它能够找到单词,但不会在richTextBox中突出显示找到的单词 有人能告诉我密码吗 谢谢 查找函数类窗体: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Win
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;
namespace Syscrawl
{
public partial class Find_Form : Form
{
FTK_Menu_Browsing_History fmbh = new FTK_Menu_Browsing_History();
public Find_Form()
{
InitializeComponent();
}
public void searchButton_Click(object sender, EventArgs e)
{
string s1 = fmbh.getSearchBrowsing().ToLower();
string s2 = textBoxSearch.Text.ToLower();
if (s1.Contains(s2))
{
MessageBox.Show("Word found!");
this.fmbh.richTextBoxBrowsing.Find(s2);
this.fmbh.richTextBoxBrowsing.SelectionLength = s2.Length;
this.fmbh.richTextBoxBrowsing.SelectionColor = Color.Red;
this.Close();
}
else
{
MessageBox.Show("Word not found!");
}
}
}
}
您需要先选择您要查找的内容。这:
int offset = s1.IndexOf(s2);
richTextBox1.Select(offset, s2.Length);
在那之后,你可以做整个高亮显示。另一个提示,为了防止选择过程中出现闪烁,请在表单中使用以下代码:
protected override void WndProc(ref Message m)
{
if (m.Msg == 0) {
if (!_doPaint)
return;
}
base.WndProc(ref m);
}
在选择任何内容之前,将_doPaint设置为false,在选择之后将其设置为true
希望我能帮忙 您需要调用
s1.IndexOf(s2,StringComparison.CurrentCultureIgnoreCase)
来查找匹配的位置
另外,它看起来像是您的Find表单创建了它自己的History表单实例;它不使用现有实例。您应该考虑接受构造函数参数。小混乱,您是否将选择的开始设置为find的结果?