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;
#region
#endregion
namespace find
{
public partial class form1 : form
{
public form1()
{
initializecomponent();
string str = "";
richtextbox1.text = str;
}
int start = 0;
int count = 0;
/// <summary>
/// 查找字符串
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void find_click(object sender, eventargs e)
{
string str1;
str1 = txt_find.text;
if (start >= richtextbox1.text.length)
{
messagebox.show("以查找到尾部");
start = 0;
}
else
{
start = richtextbox1.find(str1, start, richtextboxfinds.matchcase);
if (start == -1)
{
if (count == 0)
{
messagebox.show("没有该字符!");
}
else
{
messagebox.show("以查找到尾部!");
start = 0;
}
}
else
{
start = start + str1.length;
richtextbox1.focus();
}
}
}
/// <summary>
/// 替换字符串
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void replace_click(object sender, eventargs e)
{
richtextbox1.text = richtextbox1.text.replace(txt_find.text, txt_replace.text);
}
/// <summary>
/// 输入查找的字符串
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txt_find_textchanged(object sender, eventargs e)
{
string str1;
str1 = txt_find.text;
start = 0;
count = 0;
}
}
}
实验结果:
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论