Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

Segregator (program przechowujący ścieżki)


Rekomendowane odpowiedzi

Opublikowano

|

|

|

|

|

|

|
|

|

|

|

|

|

|

 

Cześć, chcę zaprezentować mój projekt sprzed 2 miesięcy, nazywa się Segregator.

 

Program zapisuje do pliku tekstowego wszystkie ścieżki które do niego dodamy, mogą to być dokumenty, grafika, foldery, wszystko co chcemy. Klikając dwukrotnie na taki adres dodany do programu, zadziała to tak jakbyśmy dwukrotnie kliknęli LPM.

 

Podświetla foldery na niebiesko, uszkodzone ścieżki na czerwono, pozwala je sortować, porządkować, otwierać lokalizację pliku, zliczać ilość zaznaczonych elementów, dodawać masowo wszystkie pliki z danego folderu, dodawać metodą drag&drop, modyfikować dodane ścieżki, pozwala także na wyszukiwanie.

 

Niżej screeny, download i kod. Piszcie co myślicie. Aplikacja pisana na zamówienie znajomego.

 

z7cl02.jpg

 

hsboel.jpg

 

Download:

http://www.4shared.com/zip/rGj22rRvce/Segregator.html?

Skan:

https://www.virustotal.com/pl/file/6eab763612c8dac1db5549a73bb1aceabeeb5a35e1d1cda9035dd1f4525ccab1/analysis/1400255403/

Kod:

 

 

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            listBox1.DrawMode = DrawMode.OwnerDrawFixed;   
            startreading();
            this.AllowDrop = true;
            this.DragEnter += new DragEventHandler(Form1_DragEnter);
            this.DragDrop += new DragEventHandler(Form1_DragDrop);
        }
 
        void Form1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
        }
 
        void Form1_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            foreach (string file in files)
            {
                if (listBox2.Visible == true)
                {
                    MessageBox.Show("Nie możesz dodawać w oknie segregowania!", "Informacja");
                    break;
                }
                else
                {
                    while (File.Exists(file) == true || Directory.Exists(file) == true)
                    {
                        listBox1.Items.Add(file);
                        break;
                    }
                }
                zapiszplik();
                listBox1.Items.Clear();
                startreading();
            }
        }
 
        int[] filenumbers = new int[5000];
        int[] dirnumbers = new int[5000];
        int howmany = 0;
        string path = "lista.txt";
        public void startreading()
        {
            Array.Clear(filenumbers, 0, filenumbers.Length);
            Array.Clear(dirnumbers, 0, dirnumbers.Length);
            if (File.Exists(path) != true)
            {
                MessageBox.Show("Nie można było otworzyć lista.txt!", "Błąd");
                Environment.Exit(0);
            }
 
            int which = 0, arrayfile = 0, arraydir = 0, test = 1;
            howmany = 0;
            this.listBox1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox1_DrawItem);
            foreach (var line in System.IO.File.ReadAllLines(path))
            {
                which++;
                if (File.Exists(line) != true)
                {
                    if (Directory.Exists(line) != true)
                    {
                        arrayfile++;
                        filenumbers[arrayfile] = which;
                        howmany++;
                    }
                    else
                    {
                        arraydir++;
                        dirnumbers[arraydir] = which;
                        howmany++;
                    }
                }
                listBox1.Items.Add(line);
            }
        }
 
        private void listBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
        {
            while (e.Index != -1)
            {
                // Draw the background of the ListBox control for each item.
                // Create a new Brush and initialize to a Black colored brush
                // by default.
 
                e.DrawBackground();
                Brush myBrush = Brushes.Black;
 
                // Determine the color of the brush to draw each item based on 
                // the index of the item to draw.
 
                
                for (int i = 0; i <= howmany; i++)
                {
                    if (e.Index == filenumbers[i] - 1)
                    {
                        myBrush = Brushes.Red;  //Uncorrect red colour
                        break;
                    }
                    else if (e.Index == dirnumbers[i] - 1)
                    {
                        myBrush = Brushes.Blue;  //Folder blue colour
                        break;
                    }
                    else
                        myBrush = Brushes.Black;
                }
 
               //f (test == 0)
                 // myBrush = Brushes.Orange;
 
 
                // Draw the current item text based on the current 
                // Font and the custom brush settings.
                //
 
                e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(),
                e.Font, myBrush, e.Bounds, StringFormat.GenericDefault);
 
                // If the ListBox has focus, draw a focus rectangle 
                // around the selected item.
 
                e.DrawFocusRectangle();
                break;
            }
        }
 
        private void dodajToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Aby dodać plik przeciągnij i upuść w oknie programu", "Informacja");
        }
 
        private void zamknijToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }
 
        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {
            if (listBox1.SelectedItem != null && listBox1.Visible == true)
            {
                MenuItem1.Enabled = true;
                MenuItem2.Enabled = true;
                contextMenuStrip1.Enabled = true;
            }
            else if (listBox2.SelectedItem != null && listBox2.Visible == true)
            {
                MenuItem1.Enabled = false;
                MenuItem2.Enabled = false;
                contextMenuStrip1.Enabled = true;
            }
            else
            {
                contextMenuStrip1.Enabled = false;
            }
        }
 
 
        public string s = "";
        private void MenuItem2_Click(object sender, EventArgs e)
        {
            Form2 secondForm = new Form2(1);
            if (secondForm.ShowDialog() == DialogResult.OK)
            {
                s = secondForm.issue;  
                {
                    listBox1.Items[listBox1.SelectedIndex] = s;
                    zapiszplik();
                    listBox1.Items.Clear();
                    startreading();
                }
            }
 
        }
 
        private void MenuItem1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                int x1 = 0;
                foreach (string item in listBox1.SelectedItems)
                    x1++;
                for (int x = listBox1.SelectedIndices.Count - 1; x >= 0; x--)
                {
                    if (x1 > 5)
                        if (MessageBox.Show("Nastąpi usunięcie dużej ilości plików. Jesteś pewien?", "Informacja", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            x1 = -1000;
                        else
                            break;
                    int idx = listBox1.SelectedIndices[x];
                    listBox1.Items.RemoveAt(idx);
                }
 
                zapiszplik();
                listBox1.Items.Clear();
                startreading();
            }
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            if (listBox1.Visible == true)
            {
                for (int i = 0; i < listBox1.Items.Count; i++)
                {
                    if (listBox1.Items[i].ToString().ToLower().EndsWith(textBox1.Text.ToLower()))
                    {
                        listBox1.ClearSelected();
                        listBox1.SelectedIndex = i;
                        break;
                    }
                }
            }
            else if (listBox2.Visible == true)
                for (int i = 0; i < listBox2.Items.Count; i++)
                {
                    if (listBox2.Items[i].ToString().ToLower().EndsWith(textBox1.Text.ToLower()))
                    {
                        listBox2.ClearSelected();
                        listBox2.SelectedIndex = i;
                        break;
                    }
                }
        }
 
        private void ListBox1_DoubleClick(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                try
                {
                    System.Diagnostics.Process.Start(listBox1.SelectedItem.ToString());
                }
                catch (Exception Ex)
                {
                    MessageBox.Show(Ex.Message);
                }
            }
        }
 
        private void ListBox2_DoubleClick(object sender, EventArgs e)
        {
            if (listBox2.SelectedItem != null)
            {
                try
                {
                    System.Diagnostics.Process.Start(listBox2.SelectedItem.ToString());
                }
                catch (Exception Ex)
                {
                    MessageBox.Show(Ex.Message);
                }
            }
        }
 
        private void otwórzToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                int x = 0;
                foreach (string item in listBox1.SelectedItems)
                    x++;
                foreach (string item in listBox1.SelectedItems)
                {
                    if (x > 5)
                        if (MessageBox.Show("Nastąpi otwarcie dużej ilości plików. Jesteś pewien?", "Informacja", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            x = -1000;
                        else
                            break;
                    try
                    {
                        System.Diagnostics.Process.Start(item.ToString());
                    }
                    catch (Exception Ex)
                    {
                        MessageBox.Show(Ex.Message);
                    }
                }
            }
            else if (listBox2.SelectedItem != null)
            {
                int x = 0;
                foreach (string item in listBox2.SelectedItems)
                    x++;
                foreach (string item in listBox2.SelectedItems)
                {
                    if (x > 5)
                        if (MessageBox.Show("Nastąpi otwarcie dużej ilości plików. Jesteś pewien?", "Informacja", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            x = -1000;
                        else
                            break;
                    try
                    {
                        System.Diagnostics.Process.Start(item.ToString());
                    }
                    catch (Exception Ex)
                    {
                        MessageBox.Show(Ex.Message);
                    }
                }
            }
        }
 
        private void otwórzToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                int x = 0;
                foreach (string item in listBox1.SelectedItems)
                    x++;
                foreach (string item in listBox1.SelectedItems)
                {
                    if (x > 5)
                        if (MessageBox.Show("Nastąpi otwarcie dużej ilości plików. Jesteś pewien?", "Informacja", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            x = -1000;
                        else
                            break;
                    try
                    {
                        System.Diagnostics.Process.Start(item.ToString());
                    }
                    catch (Exception Ex)
                    {
                        MessageBox.Show(Ex.Message);
                    }
                }
            }
            else if (listBox2.SelectedItem != null)
            {
                int x = 0;
                foreach (string item in listBox2.SelectedItems)
                    x++;
                foreach (string item in listBox2.SelectedItems)
                {
                    if (x > 5)
                        if (MessageBox.Show("Nastąpi otwarcie dużej ilości plików. Jesteś pewien?", "Informacja", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            x = -1000;
                        else
                            break;
                    try
                    {
                        System.Diagnostics.Process.Start(item.ToString());
                    }
                    catch (Exception Ex)
                    {
                        MessageBox.Show(Ex.Message);
                    }
                }
            }
        }
 
        private void otwórzLokalizacjęPlikuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                int x = 0;
                foreach (string item in listBox1.SelectedItems)
                    x++;
                foreach (string item in listBox1.SelectedItems)
                {
                    if (x > 5)
                        if (MessageBox.Show("Nastąpi otwarcie dużej ilości okien. Jesteś pewien?", "Informacja", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            x = -1000;
                        else
                            break;
                    try
                    {
                        System.Diagnostics.Process.Start("explorer.exe", "/select, " + item.ToString());
                    }
                    catch (Exception Ex)
                    {
                        MessageBox.Show(Ex.Message);
                    }
                }
            }
            else if (listBox2.SelectedItem != null)
            {
                int x = 0;
                foreach (string item in listBox2.SelectedItems)
                    x++;
                foreach (string item in listBox2.SelectedItems)
                {
                    if (x > 5)
                        if (MessageBox.Show("Nastąpi otwarcie dużej ilości okien. Jesteś pewien?", "Informacja", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            x = -1000;
                        else
                            break;
                    try
                    {
                        System.Diagnostics.Process.Start("explorer.exe", "/select, " + item.ToString());
                    }
                    catch (Exception Ex)
                    {
                        MessageBox.Show(Ex.Message);
                    }
                }
            }
        }
 
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("http://qentinios.pl");
        }
 
        private void pomocToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("OGÓLNE INFORMACJE:\nSegregator umożliwia zebranie plików, np muzyki, filmów rozrzuconych na dysku w jednym miejscu. Dzięki niemu nie musimy przechodzić za każdym razem do katalogów, wystarczy że klikniemy dwukrotnie na ścieżce dodanej w programie. \n\nOBSŁUGA PLIKÓW:\nAby dodać nowy plik przeciągnij go na napis w programie. Aby usunąć lub zmodyfikować plik, kliknij na ścieżce ppm. Możesz też dodać wszystkie pliki i podfoldery w jednej lokalizacji na raz, korzystając z opcji dodaj masowo. Aby zmienić jego położenie na liście skorzystaj z opcji z prawej strony.\n\nZNACZENIE KOLORÓW:\nNiebieski kolor linii jest zarezerwowany dla folderów. Czerwony kolor oznacza że ścieżka do pliku/folderu nie mogła zostać odnaleziona. Być może plik został przeniesiony lub usunięty.\n\nWYSZUKIWANIE I SORTOWANIE:\nWyszukiwanie działa od końca, tzn wpisując kilka ostatnich liter pliku (wraz z rozszerzeniem) powinniśmy go znaleść. Opcja sortuj pozwala nam wydobyć z listy tylko te elementy które nas interesują.\n\nDODATKOWE OPCJE:\nKorzystając z zakładki opcje możemy poprawić naszą listę, np kasując zdoublowane ścieżki, czy też porządkowąc ją alfabetycznie. Klikając kategorię plik mamy opcję kopiuj i zlicz. Pierwsza kopiuje ścieżkę do schowka, druga zlicza ile elementów zaznaczyliśmy.\n\nWSPARCIE:\nWszelkie uwagi oraz błędy można zgłaszać na mail: [email protected]", "Pomoc");
        }
 
        private void usuńNieprawidłoweŚcieżkiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Ta opcja skasuje wszelkie ścieżki które nie odnoszą się już do żadnego pliku lub folderu. Jesteś pewien?", "Informacja", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                listBox1.Items.Clear();
                foreach (var line in System.IO.File.ReadAllLines(path))
                {
                    if (File.Exists(line) == true || Directory.Exists(line))
                    {
                        listBox1.Items.Add(line);
                    }
                }
                zapiszplik();
                listBox1.Items.Clear();
                startreading();
            }
        }
 
        private void szukajZdoublowanychŚcieżekToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Ta opcja skasuje wszelkie ścieżki które powtarzają się. Jesteś pewien?", "Informacja", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                List<string> duplicateoption = new List<string>();
                using (StringReader reader = new StringReader(File.ReadAllText(path)))
                {
                    string line = null;
                    while ((line = reader.ReadLine()) != null)
                        if (!duplicateoption.Contains(line))
                            duplicateoption.Add(line);
                }
                using (StreamWriter writer = new StreamWriter(File.Open(path, FileMode.Create)))
                    foreach (string value in duplicateoption)
                        writer.WriteLine(value);
                listBox1.Items.Clear();
                startreading();
            }
        }
        private void zapiszplik()
        {
            using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
            {
                using (TextWriter tw = new StreamWriter(fs))
                    foreach (string item in listBox1.Items)
                        tw.WriteLine(item);
            }
        }
 
        private void kopiujToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                System.Windows.Forms.Clipboard.SetText(listBox1.SelectedItem.ToString());
            }
            else if (listBox2.SelectedItem != null)
            {
                System.Windows.Forms.Clipboard.SetText(listBox2.SelectedItem.ToString());
            }
        }
 
        private void kopiujToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                System.Windows.Forms.Clipboard.SetText(listBox1.SelectedItem.ToString());
            }
            else if (listBox2.SelectedItem != null)
            {
                System.Windows.Forms.Clipboard.SetText(listBox2.SelectedItem.ToString());
            }
        }
 
        private void folderyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (folderyToolStripMenuItem.Checked == true)
            {
                folderyToolStripMenuItem.Checked = false;
                show();
            }
            else
            {
                hide(1);
                foreach (var line in System.IO.File.ReadAllLines(path))
                {
                    if (Directory.Exists(line))
                    {
                        listBox2.Items.Add(line);
                    }
                }
            }
        }
 
        private void kategoria1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (kategoria1ToolStripMenuItem.Checked == true)
            {
                kategoria1ToolStripMenuItem.Checked = false;
                show();
            }
            else
            {
                hide(2);
                foreach (var line in System.IO.File.ReadAllLines(path))
                {
                    if (File.Exists(line))
                    {
                        listBox2.Items.Add(line);
                    }
                }
            }
        }
 
        private void rozszerzenieToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (rozszerzenieToolStripMenuItem.Checked == true)
            {
                rozszerzenieToolStripMenuItem.Checked = false;
                show();
            }
            else
            {
                hide(3);
                Form2 secondForm = new Form2(2);
                if (secondForm.ShowDialog() == DialogResult.OK)
                {
                    s = secondForm.issue;
                    {
                        for (int i = 0; i < listBox1.Items.Count; i++)
                        {
                            if (listBox1.Items[i].ToString().ToLower().EndsWith(s.ToLower()))
                            {
                                listBox2.Items.Add(listBox1.Items[i].ToString());
                            }
                        }
 
                    }
                }
            }
        }
 
        private void grafikaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (grafikaToolStripMenuItem.Checked == true)
            {
                grafikaToolStripMenuItem.Checked = false;
                show();
            }
            else
            {
                hide(4);
                for (int i = 0; i < listBox1.Items.Count; i++)
                {
                    string shortcut = listBox1.Items[i].ToString().ToLower();
                    if (shortcut.EndsWith(".jpg")||shortcut.EndsWith(".jpeg")||shortcut.EndsWith(".tiff")||shortcut.EndsWith(".png")||shortcut.EndsWith(".gif")||shortcut.EndsWith(".bmp")||shortcut.EndsWith(".xcf")||shortcut.EndsWith(".psd")||shortcut.EndsWith(".tga")||shortcut.EndsWith(".raw"))
                    {
                        listBox2.Items.Add(listBox1.Items[i].ToString());
                    }
                }
            }
        }
 
        private void muzykaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (muzykaToolStripMenuItem.Checked == true)
            {
                muzykaToolStripMenuItem.Checked = false;
                show();
            }
            else
            {
                hide(5);
                for (int i = 0; i < listBox1.Items.Count; i++)
                {
                    string shortcut = listBox1.Items[i].ToString().ToLower();
                    if (shortcut.EndsWith(".mp3") || shortcut.EndsWith(".wav") || shortcut.EndsWith(".ogg") || shortcut.EndsWith(".wma"))
                    {
                        listBox2.Items.Add(listBox1.Items[i].ToString());
                    }
                }
            }
        }
 
        private void filmyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (filmyToolStripMenuItem.Checked == true)
            {
                filmyToolStripMenuItem.Checked = false;
                show();
            }
            else
            {
                hide(6);
                for (int i = 0; i < listBox1.Items.Count; i++)
                {
                    string shortcut = listBox1.Items[i].ToString().ToLower();
                    if (shortcut.EndsWith(".3gp") || shortcut.EndsWith(".asf") || shortcut.EndsWith(".avi") || shortcut.EndsWith(".dvd") || shortcut.EndsWith(".flv") || shortcut.EndsWith(".mov") || shortcut.EndsWith(".mp4") || shortcut.EndsWith(".mpg") || shortcut.EndsWith(".ogv") || shortcut.EndsWith(".wmv"))
                    {
                        listBox2.Items.Add(listBox1.Items[i].ToString());
                    }
                }
            }
        }
 
        private void tekstToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tekstToolStripMenuItem.Checked == true)
            {
                tekstToolStripMenuItem.Checked = false;
                show();
            }
            else
            {
                hide(7);
                for (int i = 0; i < listBox1.Items.Count; i++)
                {
                    string shortcut = listBox1.Items[i].ToString().ToLower();
                    if (shortcut.EndsWith(".txt") || shortcut.EndsWith(".rtf") || shortcut.EndsWith(".doc") || shortcut.EndsWith(".docx"))
                    {
                        listBox2.Items.Add(listBox1.Items[i].ToString());
                    }
                }
            }
        }
 
        private void show()
        {
            listBox2.Visible = false;
            listBox1.Visible = true;
            kategorieToolStripMenuItem.Enabled = true;
            dodajToolStripMenuItem.Enabled = true;
            dodajMasowoToolStripMenuItem.Enabled = true;
            button2.Enabled = true;
            button3.Enabled = true;
            button4.Enabled = true;
            button5.Enabled = true;
            button6.Enabled = true;
            button7.Enabled = true;
        }
 
        private void hide(int show)
        {
            listBox1.ClearSelected();
            listBox2.Items.Clear();
            listBox1.Visible = false;
            listBox2.Visible = true;
            folderyToolStripMenuItem.Checked = false;
            kategoria1ToolStripMenuItem.Checked = false;
            rozszerzenieToolStripMenuItem.Checked = false; 
            grafikaToolStripMenuItem.Checked = false;
            muzykaToolStripMenuItem.Checked = false;
            filmyToolStripMenuItem.Checked = false;
            tekstToolStripMenuItem.Checked = false;
            kategorieToolStripMenuItem.Enabled = false;
            dodajToolStripMenuItem.Enabled = false;
            dodajMasowoToolStripMenuItem.Enabled = false;
            button2.Enabled = false;
            button3.Enabled = false;
            button4.Enabled = false;
            button5.Enabled = false;
            button6.Enabled = false;
            button7.Enabled = false;
 
            switch (show)
            {
                case 1:
                    folderyToolStripMenuItem.Checked = true;
                    break;
                case 2:
                    kategoria1ToolStripMenuItem.Checked = true;
                    break;
                case 3:
                    rozszerzenieToolStripMenuItem.Checked = true;
                    break;
                case 4:
                    grafikaToolStripMenuItem.Checked = true;
                    break;
                case 5:
                    muzykaToolStripMenuItem.Checked = true;
                    break;
                case 6:
                    filmyToolStripMenuItem.Checked = true;
                    break;
                case 7:
                    tekstToolStripMenuItem.Checked = true;
                    break;
                default:
                    break;
            }
        }
 
        private void dodajMasowoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 secondForm = new Form2(3);
            if (secondForm.ShowDialog() == DialogResult.OK)
            {
                s = secondForm.issue;
                {
                    DirSearch(s);
                    zapiszplik();
                    listBox1.Items.Clear();
                    startreading();
                }
            }
        }
 
        public void DirSearch(string sDir)
        {
            try
            {
                foreach (string f in Directory.GetFiles(sDir))
                {
                    if (!listBox1.Items.Contains(f.ToString()))
                        listBox1.Items.Add(f.ToString());
                }
 
                foreach (string d in Directory.GetDirectories(sDir))
                {
                    if (!listBox1.Items.Contains(d.ToString()))
                        listBox1.Items.Add(d.ToString());
                    DirSearch(d);
                }
            }
            catch (System.Exception excpt)
            {
                MessageBox.Show(excpt.Message);
            }
        }
 
        private void alfabetycznieAZToolStripMenuItem_Click(object sender, EventArgs e)
        {
            listBox1.Sorted = true;
            zapiszplik();
            listBox1.Items.Clear();
            startreading();
            listBox1.Sorted = false;
        }
 
        private void alfabetycznieZAToolStripMenuItem_Click(object sender, EventArgs e)
        {
            listBox2.Items.Clear();
            for (int i = listBox1.Items.Count; i > 0; i--)
            {
                if (!listBox2.Items.Contains(listBox1.Items[i - 1].ToString()))
                    listBox2.Items.Add(listBox1.Items[i-1].ToString());
            }
            listBox1.Items.Clear();
            foreach (string s in listBox2.Items)
            {
                if (!listBox1.Items.Contains(s.ToString()))
                    listBox1.Items.Add(s.ToString());
            }
            listBox2.Items.Clear();
            zapiszplik();
            //startreading();
            listBox1.Sorted = false;
        }
 
        void MoveUp(ListBox myListBox)
        {
            for (int i = 0; i < myListBox.SelectedItems.Count; i++)
            {
                int linenumber = myListBox.SelectedIndices[i];
                if (linenumber > 0 && linenumber != -1)
                {
                    myListBox.Items.Insert(linenumber - 1, myListBox.Items[linenumber]);
                    myListBox.Items.RemoveAt(linenumber + 1);
                    myListBox.SelectedIndex = linenumber - 1;
                }
            }
            zapiszplik();
        }
 
        void MoveDown(ListBox myListBox)
        {
            for (int i = myListBox.SelectedItems.Count-1; i >= 0; i--)
            {
                int linenumber = myListBox.SelectedIndices[i];
                if (linenumber >= 0 && linenumber != -1 && linenumber < listBox1.Items.Count - 1)
                {
                    myListBox.Items.Insert(linenumber + 2, myListBox.Items[linenumber]);
                    myListBox.Items.RemoveAt(linenumber);
                    myListBox.SelectedIndex = linenumber + 1;
                }
            }
            zapiszplik();
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            MoveUp(listBox1);
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            MoveDown(listBox1);
        }
 
        private void button4_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                MoveUp(listBox1);
            }
        }
 
        private void button5_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                MoveDown(listBox1);
            }
        }
 
        private void button6_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                MoveUp(listBox1);
            }
        }
 
        private void button7_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                MoveDown(listBox1);
            }
        }
 
        private void odświeżToolStripMenuItem_Click(object sender, EventArgs e)
        {
            zapiszplik();
            listBox1.Items.Clear();
            startreading();
        }
 
        private void zliczToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listBox1.Visible == true)
            {
                int i;
                for (i = 0; i < listBox1.SelectedItems.Count; i++) ;
                MessageBox.Show("Zaznaczono " + i.ToString() + " elementów!", "Informacja");
            }
            else if(listBox2.Visible == true)
            {
                int i;
                for (i = 0; i < listBox2.SelectedItems.Count; i++) ;
                MessageBox.Show("Zaznaczono " + i.ToString() + " elementów!", "Informacja");
            }
        }
    }
}

 

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication6
{
    public partial class Form2 : Form
    {
        int windowmode;
 
        public Form2(int mode)
        {
            InitializeComponent();
            if (mode == 2)
            {
                windowmode = 2;
                label1.Text = "Podaj rozszerzenie pliku (zazwyczaj 3 znaki znajdujące się po kropce w nazwie pliku)!";
            }
            else if (mode == 3)
            {
                windowmode = 3;
                label1.Text = "Podaj pełną ścieżkę do folderu, a pliki i podfoldery które zawiera zostaną dodane!";
            }
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
                MessageBox.Show("Nic nie wpisałeś!", "Informacja");
            else
            {
                if (windowmode == 2)
                {
                    this.DialogResult = DialogResult.OK;
                    this.Hide();
                    label1.Text = "Podaj nazwę pliku wraz z rozszerzeniem i kompletną ścieżką!";
                }
                else if (windowmode == 3)
                {
                    if (Directory.Exists(@textBox1.Text) != true)
                        MessageBox.Show("Taki katalog nie istnieje. Sprawdź czy nie popełniłeś błędu wpisując ścieżkę!", "Informacja");
                    else
                    {
                        this.DialogResult = DialogResult.OK;
                        this.Hide();
                        label1.Text = "Podaj nazwę pliku wraz z rozszerzeniem i kompletną ścieżką!";
                    }
                }
                else if (File.Exists(@textBox1.Text) != true && File.Exists(@textBox1.Text) != true)
                {
                    if (MessageBox.Show("Nie odnaleziono: " + textBox1.Text + ". Chcesz zmienić mimo to?", "Informacja", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        this.DialogResult = DialogResult.OK;
                        this.Hide();
                    }
                }
                else
                {
                    this.DialogResult = DialogResult.OK;
                    this.Hide();
                }
            }
        }
 
        public string issue = "";
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            issue = textBox1.Text;
        }
    }
}

 
Bugi:
  • pasek poziomy ma stałą szerokość i ucina dłuższe wpisy
  • przy przesuwaniu elementu buttonami po prawej, 'przesuwają' się też kolory (niebieski dla folderów, czerwony dla uszkodzonych ścieżek)

Edit, nie wiem czy powinno być w tym dziale czy c#, jak coś przenieście, program w visual c#.

sygnatura2.png


Opublikowano

Naturalnie,prawidłowo napisałeś temat w odpowiednim dziale.

 

Projekt bardzo dobry ile go tworzyłeś?

 

3 tygodnie na nudnych lekcjach w technikum xD

 

Dzięki za komentarz.

sygnatura2.png


Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...