Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Windows.Forms;
- namespace listboxtest
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void fastColoredTextBox1_Load(object sender, EventArgs e)
- {
- }
- List<string> FileNames = new List<string>();
- List<string> FullFileNames = new List<string>();
- private void button2_Click(object sender, EventArgs e)
- {
- using (OpenFileDialog fd = new OpenFileDialog())
- {
- fd.Multiselect = true;
- fd.Filter = "Text files|*.txt|Lua Files|*.lua";
- if (fd.ShowDialog() == DialogResult.OK)
- {
- if (listBox1.Items.Count <= 0)
- {
- fastColoredTextBox1.Text = File.ReadAllText(fd.FileName);
- }
- listBox1.Items.Add(Path.GetFileName(fd.FileName.ToString()));
- FileNames.Add(Path.GetFileName(fd.FileName.ToString()));
- FullFileNames.Add(fd.FileName.ToString());
- }
- }
- }
- private void button5_Click(object sender, EventArgs e)
- {
- fastColoredTextBox1.Clear();
- fastColoredTextBox1.Refresh();
- }
- private void listBox1_Click(object sender, EventArgs e)
- {
- if (listBox1.SelectedIndex != null) //desperate attempt to not catch a null error
- {
- if (FullFileNames.Count > 0 || listBox1.SelectedItems.Count > 0) //checks on null error within the listbox
- {
- for (int i = 0; i < FullFileNames.Count; i++) //iterate between FullName array. This is the array that stores full path files.
- {
- if (FullFileNames[i].Contains(listBox1.SelectedItem.ToString())) //check if fullfile path contains the selected listbox items
- {
- if (Path.GetExtension(FullFileNames[i]) == Path.GetExtension(listBox1.SelectedItem.ToString())) //check if the extensions are equal
- {
- fastColoredTextBox1.Text = File.ReadAllText(FullFileNames[i]); //read to fastcoloredtextbox
- break; //stop iterating.
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement