|
楼主 |
发表于 2009-1-27 18:22:53
|
显示全部楼层
if(textBox2.Text == "")
{
MessageBox.Show("Please Input a Num");
}
else
{
int input = Convert.ToInt32(textBox2.Text);
Random n = new Random();//随机数
int output=n.Next(0, input);
this.label1.Text = output.ToString();
if(this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
string select = "";//选择的那行
using(StreamReader reader = File.OpenText(this.openFileDialog1.FileName))
{
this.textBox1.Clear();
this.textBox1.Text = reader.ReadToEnd();//读入所有文本
reader.Close();
}
using(StreamReader reader = File.OpenText(this.openFileDialog1.FileName))
{
int line = 0;
while(reader.ReadLine() != null)
{
line++;
if(output-line == 1)
select =reader.ReadLine();//读入需要行的内容
}
if(output-1 > line)
MessageBox.Show("error!");
else
{
this.label4.Text = select;//显示
reader.Close();
}
}
//
} |
|