C# RichtextBox 如何获得新加入的文本
答案:2 悬赏:50 手机版
解决时间 2021-02-06 11:42
- 提问者网友:愿为果
- 2021-02-05 14:51
当有新内容加入事件发生时,我想获取新加入的内容,请问如何获取?怎么获取?
最佳答案
- 五星知识达人网友:胯下狙击手
- 2021-02-05 15:12
我用winForm做了个,你看下代码吧:
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string richString = richTextBox1.Text;
string[] richArrayString = richString.Split(' ');
int count = 1;
foreach (string rstr in richArrayString)
{
if (rstr == "fmov" || rstr == "E:\\yoli" || rstr == "E:\\test")
{
string searchString = String.Format("找到的第{0}个相关字符串为:", count) + rstr;
listBox1.Items.Add(searchString);
count++;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
}
}
}
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string richString = richTextBox1.Text;
string[] richArrayString = richString.Split(' ');
int count = 1;
foreach (string rstr in richArrayString)
{
if (rstr == "fmov" || rstr == "E:\\yoli" || rstr == "E:\\test")
{
string searchString = String.Format("找到的第{0}个相关字符串为:", count) + rstr;
listBox1.Items.Add(searchString);
count++;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
}
}
}
全部回答
- 1楼网友:旧脸谱
- 2021-02-05 16:48
代码有点多,分两次发给你,前不久写的带查找关键字高亮,希望对你有所帮助:
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);
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯