private void readData (string path)
        {
            dataGridView1.Rows.Clear ();
            StreamReader r = new StreamReader(path);
            string s = r.ReadLine ();
            while (s != null)
            {
                string [] items = s.Split (',');
 
                while (dataGridView1.ColumnCount < items.Length)
                    dataGridView1.Columns.Add ("", "");
 
                dataGridView1.Rows.Add(items);
                s = r.ReadLine();
            }
        }
                    case ".dat":
                        readData (path);
                        tabControl1.SelectedTab = dataPage;
                        break;
        private string readFile(string path)
        {
            // string result = "";
            StringBuilder builder = new StringBuilder ();
 
            StreamReader r = new StreamReader (path);
            int n = r.Read (); // first character
            while (n != -1)
            {
                char c = (char) n;
                // result += c;
                builder.Append (c);
                n = r.Read(); // next character
            }
 
            // return result;
            return builder.ToString ();            
        }
 
        private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            if (e.IsSelected)
            {
                ListViewItem item = e.Item;
                String path = item.Tag as string;
                toolStripStatusLabel1.Text = path;
                string ext = Path.GetExtension (path);
                ext = ext.ToLower ();
 
                richTextBox1.Text = "";
                pictureBox1.Image = null;
 
                switch (ext)
                {
                    case ".htm":
                    case ".html":
                        webBrowser1.Url = new Uri ("file://" + path);
                        tabControl1.SelectedTab = htmlPage;
                        break;
 
                    case ".c":
                    case ".cpp":
                    case ".pas":
                        richTextBox1.Text = readFile (path);
                        tabControl1.SelectedTab = textPage;
                        break;
 
                    case ".txt":
                        richTextBox1.LoadFile (path, RichTextBoxStreamType.PlainText);
                        tabControl1.SelectedTab = textPage;
                        break;
 
                    case ".rtf":
                        richTextBox1.LoadFile (path);
                        tabControl1.SelectedTab = textPage;
                        break;
 
                    case ".bmp":
                    case ".jpg":
                    case ".jpeg":
                        pictureBox1.Image = new Bitmap (path);
                        pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
                        tabControl1.SelectedTab = imagePage;
                        break;
                }
            }
        }
 
readfiles.txt · Last modified: 2014/12/03 11:08 by 147.32.8.115
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki