
Originally Posted by
arcon5
I wish to construct a menu within my mnuOne menu item at runtime.
I want to do it based on the structure of the folders,
files within folders are structured as follows:
Line1: Name
Line1: Location
Which would be opened using FileOpen.
How would I construct the menu at runtime in VB which creates a menu item for each file and folder in location "c:/myfolder"
E.g.
Directory c:/myfolder structure is as follows:
c:/myfolder/fil1.txt
c:/myfolder/file2.txt
c:/myfolder/directory/file1.txt
c:/myfolder/dir2/fil1.txt
I would want a menu as follows:
mnuOne/filename
mnuOne/file2name
mnuOne/directory/file1name
mnuOne/dir2/file1name
Thanks
well to get all the folders and names i suggest using the function i made.
(supply it with 2 arrays to put the paths in.)(example)
VB Code:
Public Class Form1
Dim file() As String
Dim folder() As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ReDim file(9999999)
ReDim folder(9999999)
getfiles("C:\myfolder\", file, folder)
ReDim Preserve file(filesamount - 1)
ReDim Preserve folder(foldersamount - 1)
End Sub
Dim foldersamount As Integer
Dim filesamount As Integer
Private Sub getfiles(ByVal path As String, ByVal allfiles() As String, ByVal allfolders() As String)
Dim directoryi As New IO.DirectoryInfo(path)
Dim directorys() As IO.DirectoryInfo = directoryi.GetDirectories
Dim files() As IO.FileInfo = directoryi.GetFiles
Dim directory As IO.DirectoryInfo
Dim file As IO.FileInfo
For Each file In files
allfiles(filesamount) = file.FullName
filesamount += 1
Next
For Each directory In directorys
allfolders(foldersamount) = directory.FullName
foldersamount += 1
getfiles(directory.FullName, allfiles, allfolders)
Next
End Sub
End Class
heres an example of creating a menustrip then adding to it.
VB Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim menu As New MenuStrip 'declare it
Controls.Add(menu) 'add it to the project
menu.Show() 'display the menu strip
menu.Items.Add("Test") 'add the first item
End Sub
End Class
not sure on how to add a handler or a child but that should get u started.