MKoslof
04-01-2004, 07:29 PM
A big, growing challenge for VB programmers is migrating their VB apps into the .Net Framework. One of the biggest challenges is getting Win 32 API calls and functions to run successfully in .Net. There is a learning curve between VB and VB.Net and this code sample will show you how to create a public class for implementing the popular BrowseForFolder API dialog boxes. This Public class provides several functions for calling different dialog boxes such as:
setting a default directory (the initial function I am calling with my button_click example), browsing only for other computers on a network, browsing for only directory folders, browsing for files (no call back procedure for setting the initial directory), browsing via the CISDL, etc.
Since this code piece is lengthy, it will not fit on one thread. So instead of breaking the code up over several threads (this may get confusing) I have copied the whole code piece into a text file. This text file is attached. It will open in any text editor, such as TexPad or NotePad. You can simply copy this code into a standard module..it should work as is. I recommend using it in the 1.1 Framework, I have not tested it in 1.0, but I imagine it would still compile OK. To call any of the functions in this public class, say in a button click, you simply have to instantiate a new class instance like so:
In the New clsFolderBrowser constructor, you just need to pass in the handle you want, I have signified that by putting "handle" in the slot provided.
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strString As String
Dim xClass As clsFolderBrowser = New clsFolderBrowser(Handle)
strString = xClass.BrowseForFiles("C:\Testing")
Me.TextBox1.Text = strString
End Sub
setting a default directory (the initial function I am calling with my button_click example), browsing only for other computers on a network, browsing for only directory folders, browsing for files (no call back procedure for setting the initial directory), browsing via the CISDL, etc.
Since this code piece is lengthy, it will not fit on one thread. So instead of breaking the code up over several threads (this may get confusing) I have copied the whole code piece into a text file. This text file is attached. It will open in any text editor, such as TexPad or NotePad. You can simply copy this code into a standard module..it should work as is. I recommend using it in the 1.1 Framework, I have not tested it in 1.0, but I imagine it would still compile OK. To call any of the functions in this public class, say in a button click, you simply have to instantiate a new class instance like so:
In the New clsFolderBrowser constructor, you just need to pass in the handle you want, I have signified that by putting "handle" in the slot provided.
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strString As String
Dim xClass As clsFolderBrowser = New clsFolderBrowser(Handle)
strString = xClass.BrowseForFiles("C:\Testing")
Me.TextBox1.Text = strString
End Sub