Imports System.Windows.Forms
' This class is needed because the
' System.Windows.Forms.Design.FolderNameEditor.FolderBrowser is Protected and thus
' is not accessible in this context. Deriving a Public class from it enables you to
' use the dialog in your code.
Public Class FolderBrowser
Inherits System.Windows.Forms.Design.FolderNameEditor
Public Shared Function ShowDialog() As String
Dim fb As New FolderBrowser()
fb.Description = "Select a Directory to Scan"
fb.Style = Design.FolderNameEditor.FolderBrowserStyles.RestrictToFilesystem
fb.ShowDialog()
Return fb.DirectoryPath
End Function
End Class
jjjamie said:I posted a lengthy reply to this but it hasn't been copied across from the old forum (www.visualbasicforum.com). Thanks for your help guys.
[edit]Here you go - divil[/edit]
Thanks guys
I was looking at the source code and this is what I found:
Visual Basic:Imports System.Windows.Forms ' This class is needed because the ' System.Windows.Forms.Design.FolderNameEditor.FolderBrowser is Protected and thus ' is not accessible in this context. Deriving a Public class from it enables you to ' use the dialog in your code. Public Class FolderBrowser Inherits System.Windows.Forms.Design.FolderNameEditor Public Shared Function ShowDialog() As String Dim fb As New FolderBrowser() fb.Description = "Select a Directory to Scan" fb.Style = Design.FolderNameEditor.FolderBrowserStyles.RestrictToFilesystem fb.ShowDialog() Return fb.DirectoryPath End Function End Class
Why have Microsoft made the class protected? They have given no documentation on the FolderBrowser class. In the help files it says 'The FolderNameEditor.FolderBrowser type supports the .NET Framework infrastructure and is not intended to be used directly from your code.'.
I find this strange us I have seen a lot of people on forums asking how to create one. (Now I know the answer!)
Cheers.