错误 1 当前上下文中不存在名称“index”
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 System.IO;
namespace SY3_3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btOpen_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = "*.txt";
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "Text Files(*.Txt|*.Txt|All Files(*.*)|*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName == null || openFileDialog1.FileName.Equals(""))
return;
int a;
FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
tbInfo.Text = "";
a = fs.ReadByte();
while (a != -1)
{
tbInfo.Text += ((char)a).ToString();
a = fs.ReadByte();
}
fs.Close();
}
private void btSave_Click(object sender, EventArgs e)
{
saveFileDialog1.InitialDirectory = "c:\\";
saveFileDialog1.Filter = "Text Files(*.Txt|*.Txt|All Files(*.*)|*.*";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.ShowDialog();
if (openFileDialog1.FileName == null || openFileDialog1.FileName.Equals(""))
return;
byte a;
FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.OpenOrCreate, FileAccess.Write);
for (int i = 0; i < tbInfo.Text.Length; i++)
{
a = (byte)tbInfo.Text[i];
fs.WriteByte(a);
}
fs.Flush();
fs.Close();
}
private void btSeach_Click(object sender, EventArgs e)
{
tbInfo.Focus();
index = tbInfo.Text.IndexOf("SOA", index);
if (index >= 0)
{
tbInfo.SelectionStart = index;
tbInfo.SelectionLength = 4;
index++;
}
else
MessageBox.Show("找不到!");
}
private void btClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
请问怎么弄啊???