Dialógové okno BrowseForFolder spigi - 5. 3. 2003 12:03 - 6852 views Tak ma napadlo, ako by sa dalo otvoriť dialógové okno v .NET na výber adresára, niečo ako poskytovala API funkcia ShBrowseForFolder. Po troške pátrania v .NET Frameworku, som prišiel na to, že v .NET Frameworku neexistuje priamo funkcia, ktorá by mi s týmto pomohla. A tak prišiel na rad internet :-) Podľa informácii z Microsoftu vo verzii .NET Framework 1.1 (ktorá má výjsť v najbližšej dobe, spolu s Visual Studio 2003 a Windows 2003 Servrom) má byť v namespace System.Windows.Forms tieda System.Windows.Forms.FolderBrowserDialog. Opravené 16.3.2003.: Dnes som si úspešne nainštaloval .NET Framework 1.1 a musim potvrďiť, že táto trieda už je obsiahnutá v tejto verzii. Lenže v stávajúcej verzii 1.0 neexistuje a tak máme dve možnosti. 1. Použiť COM Interop a naďalej používať API funkciu ... príklad nájdete na webe Microsoftu http://support.microsoft.com/default.aspx?scid=kb;en-us;Q306285. Na tejto stránke je kompletný popis a aj zdrojový kód ukážkovej aplikácie. 2. Na webe www.wintoolzone.com nájdete DLL Assembly, ktorá obsahuje túto funkciu a je kompletne napísaná v managed code. http://www.wintoolzone.com/downloads/bd.zip Doplnené 9.4.2003. Niekde na webe som ešte našiel jedno riešenie. Potrebujeme si pridať referenciu na System.Design.dll Class BrowseForFoldersDialogClass BrowseForFoldersDialog ' the Description that appears in the dialog Dim m_Description As String Property Description() As String Get Return m_Description End Get Set(ByVal Value As String) m_Description = Value End Set End Property ()Property ' the path returned by the dialog Dim m_Path As String Property Path() As String Get Return m_Path End Get Set(ByVal Value As String) m_Path = Value End Set End Property ()Property ' the ShowDialog method Function ShowDialog() As System.Windows.Forms.DialogResult Dim fb As New FolderBrowser(Me) Return fb.ShowDialog() End Function ()Function ' an inner private class that inherits from a .NET Framework class ' we need this class because we want to access protected members Private Class FolderBrowserClass FolderBrowser Inherits System.Windows.Forms.Design.FolderNameEditor Dim parent As BrowseForFoldersDialog ' store a reference to the outer object, so that its ' private properties can be accessed Sub New(ByVal parent As BrowseForFoldersDialog) Me.parent = parent End Sub ()Sub ' show the dialog Function ShowDialog() As System.Windows.Forms.DialogResult Dim fb As New _ System.Windows.Forms.Design.FolderNameEditor.FolderBrowser() fb.Description = parent.m_Description ShowDialog = fb.ShowDialog() If ShowDialog = Windows.Forms.DialogResult.OK Then parent.m_Path = fb.DirectoryPath End If End Function End()Function End Class End ClassClassEnd Class