Public Class Form1
    Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.Click
        If MouseButtons = MouseButtons.Right Then
            ContextMenuStrip1.Show()
        End If
    End Sub
    Private Sub DelRabot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DelRabot.Click
        If ListBox1.SelectedItem <> "" Then
            ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
            ComboBox1.Items.RemoveAt(ComboBox1.SelectedIndex)
        Else
            MsgBox("Выберите студента для удаления")
        End If
    End Sub
    Private Sub AddRabot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddRabot.Click
        Dim добавляем As String
        добавляем = InputBox("Введите ФИО студента", "1-го курса", "")
        ListBox1.Items.Add(добавляем)
        ComboBox1.Items.Add(добавляем)
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button3.Enabled = False
        ListBox1.Enabled = False
    End Sub
    Dim lines() As String
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenFileDialog1.Filter = ".TXT|*.txt"
        If OpenFileDialog1.ShowDialog = DialogResult.Cancel Then Exit Sub

        lines = IO.File.ReadAllLines(OpenFileDialog1.FileName, System.Text.Encoding.GetEncoding(1251))

        For i As Integer = 0 To lines.Length - 1
            Button3.Enabled = True
            ListBox1.Enabled = True
            ComboBox1.Items.Add(lines(i))
            ListBox1.Items.Add(lines(i))
        Next
  
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If ListBox1.Items.Count <> 0 Then
            For i As Integer = 0 To ListBox1.Items.Count - 1
                TextBox1.Text += ListBox1.Items.Item(i) & vbCrLf
            Next
            IO.File.WriteAllText(IO.Directory.GetCurrentDirectory & "\Первый курс.txt", TextBox1.Text, System.Text.Encoding.GetEncoding(1251))
            MsgBox("Список сохранен в файл. Его путь : " & IO.Directory.GetCurrentDirectory & "\Первый курс.txt")
        Else
            MsgBox("Заполните список.")
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Application.Restart()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        ListBox1.Items.Clear()
        ComboBox1.Items.Clear()
    End Sub
End Class
