vb 中的菜单条功能



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

你能给我帮助的任何来源都会很棒! 谢谢!

Sub Main()
    Dim objReader As New StreamReader("C:UsersHPG62-220USDocumentsVisual Studio 2010ProjectsAssignement 8Assignement 8binDebugBooks.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
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

相关内容

  • 没有找到相关文章

最新更新