linksanime2003
12-21-2004, 03:21 PM
What I'm trying to do is to change the items in a context menu after it has loaded.
A form is loaded, and it lets you change items in the context menu. It save these to a file, and tis file is then read to create the menu. Now, the first time this form is loaded, this change works great. However, when I load the form again and do the same thing, the menu items do not show up at all.
I don't know exactly what code is needed, but here is the stuff that actually changes the menu items.
Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
Dim FriendsList As String = Application.StartupPath & "\friends.data"
Dim FriendsListFileStream As New System.IO.FileStream(FriendsList, IO.FileMode.Open)
Dim FriendsListReader As New System.IO.StreamReader(FriendsListFileStream)
Dim i As Integer = 0
Dim FriendsLine As String
MainForm.mnuNotifyFriends.MenuItems.Clear()
While i = 0
FriendsLine = FriendsListReader.ReadLine()
If FriendsLine = "" Then
' Nothing
Exit While
ElseIf FriendsLine <> "" Then
MainForm.mnuNotifyFriends.MenuItems.Add(FriendsLine)
End If
End While
FriendsListReader.Close()
FriendsListFileStream.Close()
Me.Close()
End Sub
A form is loaded, and it lets you change items in the context menu. It save these to a file, and tis file is then read to create the menu. Now, the first time this form is loaded, this change works great. However, when I load the form again and do the same thing, the menu items do not show up at all.
I don't know exactly what code is needed, but here is the stuff that actually changes the menu items.
Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
Dim FriendsList As String = Application.StartupPath & "\friends.data"
Dim FriendsListFileStream As New System.IO.FileStream(FriendsList, IO.FileMode.Open)
Dim FriendsListReader As New System.IO.StreamReader(FriendsListFileStream)
Dim i As Integer = 0
Dim FriendsLine As String
MainForm.mnuNotifyFriends.MenuItems.Clear()
While i = 0
FriendsLine = FriendsListReader.ReadLine()
If FriendsLine = "" Then
' Nothing
Exit While
ElseIf FriendsLine <> "" Then
MainForm.mnuNotifyFriends.MenuItems.Add(FriendsLine)
End If
End While
FriendsListReader.Close()
FriendsListFileStream.Close()
Me.Close()
End Sub