找回密码
 注册
搜索
热搜: java php web
查看: 1533|回复: 2

求助 一个C#简单的小程序!

[复制链接]
发表于 2009-1-27 17:48:25 | 显示全部楼层 |阅读模式
问题已解决
 楼主| 发表于 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();

                                                }
                                                
                                        }


                                       
                                        //
                                }
回复

使用道具 举报

发表于 2009-1-27 19:13:49 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|软晨网(RuanChen.com)

GMT+8, 2024-9-20 13:52

Powered by Discuz! X3.5

Copyright © 2001-2023 Tencent Cloud.

快速回复 返回顶部 返回列表