Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.50 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.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace WinFormExpl
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         FileInfo loadedFile = null;
  17.         int counter;
  18.         readonly int counterInitialValue;
  19.  
  20.  
  21.         public Form1()
  22.         {
  23.             InitializeComponent();
  24.             counterInitialValue = 40;
  25.         }
  26.  
  27.         private void miOpen_Click(object sender, EventArgs e)
  28.         {
  29.             InputDialog dlg = new InputDialog();
  30.             if (dlg.ShowDialog() == DialogResult.OK)
  31.             {
  32.                 string result = dlg.Path;
  33.                 //MessageBox.Show(result);
  34.                 // TODO: további lépések...
  35.                 listView1.Items.Clear();
  36.                 if(Directory.Exists(result))
  37.                 {
  38.                     foreach (string s in Directory.GetFiles(result))
  39.                     {
  40.                         FileInfo fi = new FileInfo(s);
  41.                         var item = listView1.Items.Add(new ListViewItem(new string[] {fi.Name, fi.Length.ToString()}));
  42.                         item.Tag = fi.FullName;
  43.                     }
  44.                 }
  45.             }
  46.  
  47.         }
  48.  
  49.         private void miExit_Click(object sender, EventArgs e)
  50.         {
  51.             Close();
  52.         }
  53.  
  54.         private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  55.         {
  56.  
  57.             if(listView1.SelectedItems.Count == 0)
  58.             {
  59.                 lName.Text = "Name:";
  60.                 lCreated.Text = "Created:";
  61.             }
  62.  
  63.             else
  64.             {
  65.                 string name = listView1.SelectedItems[0].Text;
  66.                 lName.Text = "Name: " + name;
  67.  
  68.                 FileInfo fi = new FileInfo(listView1.SelectedItems[0].Tag.ToString());
  69.                 lCreated.Text = "Created: " + fi.CreationTime;
  70.             }
  71.         }
  72.  
  73.         private void listView1_DoubleClick(object sender, EventArgs e)
  74.         {
  75.            
  76.             if (listView1.SelectedItems.Count == 1)
  77.             {
  78.                 counter = counterInitialValue;
  79.                 loadedFile = new FileInfo(listView1.SelectedItems[0].Tag.ToString());
  80.                 reloadTimer.Start();
  81.                 try
  82.                 {
  83.                     tContent.Text = File.ReadAllText(listView1.SelectedItems[0].Tag.ToString());
  84.                 }
  85.                 catch (Exception ex)
  86.                 {
  87.  
  88.                 }
  89.             }
  90.             else
  91.             {
  92.                 tContent.Clear();
  93.             }
  94.            
  95.         }
  96.  
  97.         private void reloadTimer_Tick(object sender, EventArgs e)
  98.         {
  99.             counter--;
  100.             // Fontos! Ez váltja ki a Paint eseményt és ezzel a
  101.             // a téglalap újrarajzolását
  102.             detailsPanel.Invalidate();
  103.             if (counter <= 0)
  104.             {
  105.                 counter = counterInitialValue;
  106.                 tContent.Text = File.ReadAllText(loadedFile.FullName);
  107.             }
  108.         }
  109.  
  110.         private void detailsPanel_Paint(object sender, PaintEventArgs e)
  111.         {
  112.             //((counterInitialValue-counter)/counterInitialValue)*120
  113.             if (loadedFile != null)
  114.                 e.Graphics.FillRectangle(new SolidBrush(Color.Green), 0, 0, (1-((counterInitialValue - counter) / counterInitialValue)) * 120, 5);
  115.  
  116.         }
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement