0

我正在尝试编写一个程序,在其中读取文本文件,然后为用户提供一些选项来查看文件中的不同书籍。我正在前进,但我在弄清楚如何让用户从菜单条下拉项目中选择不同的选项时遇到问题。例如,我有在我的代码中完成的退出按钮和保存按钮(顺便说一句,这不起作用,但我正在研究如何修复它),但我也将添加、删除和更新按钮作为以及用于显示文本文件中某些内容的按钮。

您可以给我帮助的任何资源都会很棒!谢谢!

Sub Main()
    Dim objReader As New StreamReader("C:\Users\HPG62-220US\Documents\Visual Studio 2010\Projects\Assignement 8\Assignement 8\bin\Debug\Books.txt")
    Dim sLine As String = ""
    Dim arrayText As New ArrayList()

    Do
        sLine = objReader.ReadLine()
        If Not sLine Is Nothing Then
            arrayText.Add(sLine)
        End If
    Loop Until sLine Is Nothing
    objReader.Close()

    For Each sLine In arrayText
        Console.WriteLine(sLine)
    Next
    Console.ReadLine()

End Sub

Private Sub ExitToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ExitToolStripMenuItem.Click
    Me.Close()

End Sub

Private Sub SaveToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SaveToolStripMenuItem.Click

    Using writer As StreamWriter = New StreamWriter("book list.txt", True)
        For Each line As String In lstBooks.Items
            writer.WriteLine(line)
        Next
    End Using
End Sub

Private Sub Delete_Click(sender As System.Object, e As System.EventArgs) Handles Delete.Click


End Sub
4

1 回答 1

0
Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
  'We have MenuStrip1 which has a "Documents" top level menuitem
  'Dynamically add 3 options to it

  Dim doc1 As New ToolStripMenuItem("Doc1")
  doc1.Tag = "Snow White" 'some identifying data so we can tell it apart in the event handler
  DocumentsToolStripMenuItem.DropDownItems.Add(doc1)
  AddHandler doc1.Click, AddressOf Doc_Click

  Dim doc2 As New ToolStripMenuItem("Doc2")
  doc2.Tag = "War and Peace"
  DocumentsToolStripMenuItem.DropDownItems.Add(doc2)
  AddHandler doc2.Click, AddressOf Doc_Click

  Dim doc3 As New ToolStripMenuItem("Doc3")
  doc3.Tag = "Dictionary"
  DocumentsToolStripMenuItem.DropDownItems.Add(doc3)
  AddHandler doc3.Click, AddressOf Doc_Click

  'remove the middle one
  DocumentsToolStripMenuItem.DropDownItems.Remove(doc2)

End Sub


Private Sub Doc_Click(sender As System.Object, e As System.EventArgs)
  Dim tsmi As ToolStripMenuItem = DirectCast(sender, ToolStripMenuItem)
  Select Case tsmi.Tag.ToString
    Case "Snow White"
      MsgBox("Don't eat the apple")
    Case "War and Peace"
      MsgBox("Tolstoy")
    Case "Dictionary"
      MsgBox("Blah")
  End Select
End Sub
于 2012-10-05T00:55:41.970 回答