Advertisement
mateusz1239196

Notatki - Source Code

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