Advertisement
JohnDoee123

Untitled

Sep 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.IO;
  10.  
  11. using System.Windows.Forms;
  12.  
  13. namespace listboxtest
  14. {
  15. public partial class Form1 : Form
  16. {
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21.  
  22. private void Form1_Load(object sender, EventArgs e)
  23. {
  24.  
  25. }
  26.  
  27. private void fastColoredTextBox1_Load(object sender, EventArgs e)
  28. {
  29.  
  30. }
  31.  
  32. List<string> FileNames = new List<string>();
  33. List<string> FullFileNames = new List<string>();
  34. private void button2_Click(object sender, EventArgs e)
  35. {
  36. using (OpenFileDialog fd = new OpenFileDialog())
  37. {
  38. fd.Multiselect = true;
  39. fd.Filter = "Text files|*.txt|Lua Files|*.lua";
  40. if (fd.ShowDialog() == DialogResult.OK)
  41. {
  42. if (listBox1.Items.Count <= 0)
  43. {
  44. fastColoredTextBox1.Text = File.ReadAllText(fd.FileName);
  45. }
  46.  
  47. listBox1.Items.Add(Path.GetFileName(fd.FileName.ToString()));
  48. FileNames.Add(Path.GetFileName(fd.FileName.ToString()));
  49. FullFileNames.Add(fd.FileName.ToString());
  50. }
  51. }
  52. }
  53.  
  54. private void button5_Click(object sender, EventArgs e)
  55. {
  56. fastColoredTextBox1.Clear();
  57. fastColoredTextBox1.Refresh();
  58. }
  59.  
  60. private void listBox1_Click(object sender, EventArgs e)
  61. {
  62. if (listBox1.SelectedIndex != null) //desperate attempt to not catch a null error
  63. {
  64. if (FullFileNames.Count > 0 || listBox1.SelectedItems.Count > 0) //checks on null error within the listbox
  65. {
  66. for (int i = 0; i < FullFileNames.Count; i++) //iterate between FullName array. This is the array that stores full path files.
  67. {
  68. if (FullFileNames[i].Contains(listBox1.SelectedItem.ToString())) //check if fullfile path contains the selected listbox items
  69. {
  70. if (Path.GetExtension(FullFileNames[i]) == Path.GetExtension(listBox1.SelectedItem.ToString())) //check if the extensions are equal
  71. {
  72. fastColoredTextBox1.Text = File.ReadAllText(FullFileNames[i]); //read to fastcoloredtextbox
  73. break; //stop iterating.
  74. }
  75. }
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement