搜索下一个如何实现?

fly_flin 2012-05-18 11:19:43
这是搜索pdf中第一个 textBox1.Text中字符串 的位置并显示,请问如何修改可以实现点一下然后显示pdf中第二个字符串的位置??
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{

}

private int FindTextForPDF(string pdfFile)
{

string strFindText1 = this.textBox1.Text;
int findText = -1;
string[] lst = new string[] { };
string strTemp = "d:\\b.txt";
using (PDFWrapper pdf = new PDFWrapper(""))
{

pdf.LoadPDF(pdfFile);
pdf.ExportText(strTemp, 1, pdf.PageCount, false, true);
using (System.IO.StreamReader reader = new System.IO.StreamReader(strTemp))
{
string strOut = reader.ReadToEnd();
lst = strOut.Split('');
}
}

for (int i = 0; i < lst.Length; i++)
{
if (lst[i].IndexOf(strFindText1) > 0)
{
findText = i;
break;
}
}
return findText;
}

private void button1_Click(object sender, EventArgs e)
{
int m = FindTextForPDF("D:\\777_BEJ_PP_D633W101-BEJ_TD\\PDF\\23.PDF");
string fileName = "D:\\777_BEJ_PP_D633W101-BEJ_TD\\PDF\\23.PDF";
axAcroPDF1.LoadFile(fileName);
axAcroPDF1.setCurrentPage(m + 1);//里面的数字就是打开时的页面
axAcroPDF1.Show();
}
...全文
122 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
fly_flin 2012-05-18
  • 打赏
  • 举报
回复
if (lst[i].IndexOf(strFindText1) > 0)在这里显示索引超出了数组界限,怎么改??本人小白。。。
[Quote=引用 1 楼 的回复:]
int findText = -1;//定义为全局变量
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{

}

private int FindTextForPDF(string pdfF……
[/Quote]
test2050 2012-05-18
  • 打赏
  • 举报
回复

int findText = -1;//定义为全局变量
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{

}

private int FindTextForPDF(string pdfFile)
{

string strFindText1 = this.textBox1.Text; string[] lst = new string[] { };
string strTemp = "d:\\b.txt";
using (PDFWrapper pdf = new PDFWrapper(""))
{

pdf.LoadPDF(pdfFile);
pdf.ExportText(strTemp, 1, pdf.PageCount, false, true);
using (System.IO.StreamReader reader = new System.IO.StreamReader(strTemp))
{
string strOut = reader.ReadToEnd();
lst = strOut.Split(' ');
}
}

for (int i = findText ; i < lst.Length; i++)//每按一次就查找下一个
{
if (lst[i].IndexOf(strFindText1) > 0)
{
findText = i;
break;
}
}
return findText;
}

private void button1_Click(object sender, EventArgs e)
{
int m = FindTextForPDF("D:\\777_BEJ_PP_D633W101-BEJ_TD\\PDF\\23.PDF");
string fileName = "D:\\777_BEJ_PP_D633W101-BEJ_TD\\PDF\\23.PDF";
axAcroPDF1.LoadFile(fileName);
axAcroPDF1.setCurrentPage(m + 1);//里面的数字就是打开时的页面
axAcroPDF1.Show();
}

axAcroPDF1的show与close自己再控制控制

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧