Advertisement
mateusz1239196

Notatki - Source Code

Oct 10th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.62 KB | None | 0 0
  1. ' form1
  2.  
  3.  
  4. Public Class Form1
  5.     Public path As String
  6.     Public nazwapliku
  7.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  8.         ' Zapisuje tekst
  9.         If TextBox1.Text = "" Then
  10.             MsgBox("Nazwij notatkę!")
  11.         Else
  12.             My.Computer.FileSystem.WriteAllText(path & ("/") & TextBox1.Text & (".txt"), RichTextBox1.Text, False)
  13.         End If
  14.         ' ponownie sprawdza pliki w folderze
  15.         Dim fileNames = My.Computer.FileSystem.GetFiles(path, FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
  16.         ListBox1.Items.Clear()
  17.         For Each fileName As String In fileNames
  18.             Dim nazwapliku As String = My.Computer.FileSystem.GetName(fileName)
  19.             nazwapliku = nazwapliku.Remove(nazwapliku.Length - 4)
  20.             ListBox1.Items.Add(nazwapliku)
  21.         Next
  22.     End Sub
  23.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  24.         'sprawdza czy jest to pierwsze uruchomienie
  25.         If My.Computer.FileSystem.FileExists(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "/notatki.txt") Then
  26.             path = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "/notatki.txt") & "\"
  27.             'wczytuje pliki z path do listboxa
  28.             Dim fileNames = My.Computer.FileSystem.GetFiles(path, FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
  29.             ListBox1.Items.Clear()
  30.             For Each fileName As String In fileNames
  31.                 Dim nazwapliku As String
  32.                 nazwapliku = My.Computer.FileSystem.GetName(fileName)
  33.                 nazwapliku = nazwapliku.Remove(nazwapliku.Length - 4)
  34.                 ListBox1.Items.Add(nazwapliku)
  35.             Next
  36.         Else
  37.             Form2.Show()
  38.         End If
  39.     End Sub
  40.     Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
  41.         ' wyświetla tekst po wybraniu itemu w itemboxie
  42.         RichTextBox1.Text = My.Computer.FileSystem.ReadAllText(path & ListBox1.SelectedItem & ".txt")
  43.         TextBox1.Text = ListBox1.SelectedItem
  44.     End Sub
  45.  
  46.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  47.         ' usuwa wybrany plik
  48.         Dim result As Integer = MessageBox.Show("Po usunięciu pliku nie będzie można odzyskać Usunąć?", "Usunąć?", MessageBoxButtons.YesNo)
  49.         If result = DialogResult.Yes Then
  50.             My.Computer.FileSystem.DeleteFile(path & ListBox1.SelectedItem & ".txt")
  51.             TextBox1.Text = ""
  52.         End If
  53.         ' refresh listboxa
  54.         Dim fileNames = My.Computer.FileSystem.GetFiles(path, FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
  55.         ListBox1.Items.Clear()
  56.         For Each fileName As String In fileNames
  57.             nazwapliku = My.Computer.FileSystem.GetName(fileName)
  58.             nazwapliku = nazwapliku.Remove(nazwapliku.Length - 4)
  59.             ListBox1.Items.Add(nazwapliku)
  60.         Next
  61.     End Sub
  62.  
  63.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  64.         RichTextBox1.Text = ""
  65.     End Sub
  66.  
  67.     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  68.         ' zmienia nazwę notatki
  69.         If TextBox1.Text = ListBox1.SelectedItem Then
  70.             MsgBox("Zmień nazwę notatki!")
  71.         Else
  72.             My.Computer.FileSystem.RenameFile(path & ListBox1.SelectedItem & ".txt", TextBox1.Text & ".txt")
  73.         End If
  74.         ' refresh listboxa
  75.         Dim fileNames = My.Computer.FileSystem.GetFiles(path, FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
  76.         ListBox1.Items.Clear()
  77.         For Each fileName As String In fileNames
  78.             nazwapliku = My.Computer.FileSystem.GetName(fileName)
  79.             nazwapliku = nazwapliku.Remove(nazwapliku.Length - 4)
  80.             ListBox1.Items.Add(nazwapliku)
  81.         Next
  82.     End Sub
  83.  
  84.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  85.         Form2.Show()
  86.     End Sub
  87.  
  88.     Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
  89.         TextBox1.Text = ""
  90.         RichTextBox1.Text = ""
  91.     End Sub
  92. End Class
  93.  
  94. 'form2
  95.  
  96. Public Class Form2
  97.     Public path As String
  98.  
  99.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  100.         ' wybieranie miejsca zapisu
  101.         FolderBrowserDialog1.ShowDialog()
  102.         TextBox1.Text = FolderBrowserDialog1.SelectedPath
  103.         path = FolderBrowserDialog1.SelectedPath
  104.     End Sub
  105.  
  106.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  107.         ' sprawdza poprawność
  108.         If path = "" Then
  109.             MsgBox("Wybierz miejsce zapisu!")
  110.         Else
  111.             ' zapisuje do ścieżkę do pliku
  112.             My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "/notatki.txt", path, False)
  113.             path = FolderBrowserDialog1.SelectedPath
  114.             Me.Close()
  115.             Form1.Show()
  116.         End If
  117.     End Sub
  118.     Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
  119.         MsgBox("E-mail do twórcy: mateusz1239196@gmail.com")
  120.     End Sub
  121.  
  122.     Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  123.         Form1.Hide()
  124.     End Sub
  125. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement