Skip to main content
Email Password   helpLost your password?

Introduction

The great thing about OOP and .NET is that you should never have to find yourself coding the same thing over and over again. Reusability is the name of the game. So when I recently found myself in the vicious cycle of re-coding the same interface component, I thought that surely there was a better way.

Background

I frequently need to create little "wizards" and other applications that work with files and folders. The "industry standard" way of locating these resources is to put a TextBox on the page, and a little icon of a folder next to that, and use the icon folder to launch the browse dialog, storing the results in the TextBox. Surely, you've seen this a thousand times, and if you were building a web application, there is already an object to do this. Not so in Windows Forms, however.

Every time I needed to use this functionality, I had to:

Well, that's a lot of coding to do over and over. And I got tired of it. So I created the BrowseField.

Features of the BrowseField

Using the BrowseField control is as simple as dropping it onto a page, setting the properties up the way you like them in the IDE, and then querying the Text value for the result. Or, you could set the properties programmatically like this:

BrowseField1.Caption = "This is my label text"
BrowseField1.CaptionStyle = BrowseField.CaptionStyles.Top
BrowseField1.FileDialogFilter = "All Files (*.*)|*.*"
BrowseField1.FileDialogFilterIndex = 1
BrowseField1.BrowseType = BrowseField.BrowseTypes.File
BrowseField1.BorderStyle = BorderStyle.FixedSingle

Note that you do not need to setup any code to display the dialog boxes, handle drag and drop operations, or handle resizing operations. For the most part, any changes you make are purely cosmetic. It just works.

BrowseList

Shortly after releasing the BrowseField control, I realized that I often used a ListBox control in much the same way - to gather multiple folder and file names. This is even more of a hassle than using the TextBox, as I usually add several PictureBox controls used to Add, Delete and Edit the paths entered. Checks for duplicate paths are needed as well. And in my opinion, some critical events were left out of the ListBox control - ItemAdded(), ItemRemoved(), and ItemChanged(). These needed to be implemented too.

Features of BrowseList

I think I should also mention that both controls are written in VB.NET. However, as you already know, that won't stop it from working with C# or any other .NET compliant language. There isn't a great deal of commenting in the code - as this is really more of a tool than a tutorial, I didn't see the need for it. Also, since these are composite controls, they are very simple in nature.

Licensing

I always like to list my projects as "ThankYouWare". That is, if you use them, please send me a "Thank You" email letting me know if you like them, and any features or improvements you'd like to see. The controls are open source, you may modify them at will (just don't ask me to fix your modified code). If you redistribute the original or modified code, please credit me somewhere, even if it's just in the code comments.

Breaking Changes

While I hate to make "breaking changes" in controls, I thought it was necessary with this control. The original versions of these controls had a minimal interface, and instead of providing access to the child controls through shadowed properties, I simply exposed the child controls directly. This worked, and certainly exposed every aspect of the child controls to the programmer, but it allowed the programmer to "break" the functionality of the code, and wasn't VS.NET-IDE friendly. (Changes made in the properties grid of the IDE tended to disappear randomly.) Frankly, it was just poor programming.

In version 2, all the important properties and events have been exposed directly. Now the programmer cannot "break" the control's built-in validation and security. It also means that the controls play nice with the IDE. As well, the Caption (Label) is entirely new.

Known Problems

There is a funny little "bug" in the resizing of the controls sometimes. For example, if you open the sample project and change drag the form's width so that it is very small, then re-expand it, the right side of the browse controls goes off the edge of the form. I'm not sure why this is taking place. Also, while very minor, there are icons associated with the controls, but they don't appear to be showing up. If anyone knows of a fix to these problems, I'll be happy to update the code and credit you in the code as well. Thanks.

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralWeb Application Pin
malhotrm
17:09 2 May '07  
GeneralRe: Web Application Pin
jagadishdandin
21:58 17 May '07  
GeneralIs it possible to have the buttons as a separate control? Pin
mlyons
9:23 25 Apr '07  
GeneralRe: Is it possible to have the buttons as a separate control? Pin
Todd Davis
9:30 25 Apr '07  
QuestionTextChanged Event not visible Pin
SkipSnyder
18:12 6 Apr '07  
GeneralSo... how do I use it? Pin
Perry2
13:00 13 Mar '07  
GeneralRe: So... how do I use it? Pin
Todd Davis
16:05 13 Mar '07  
GeneralThanks Pin
datlq2003@yahoo.com
23:10 11 Apr '06  
GeneralCurrentDirectory Changed Pin
Josema
7:04 8 Mar '06  
GeneralDiscussion: Shall the ListBox1 be public? Pin
FauthD
4:49 20 Oct '05  
GeneralAdditional event for BrowseList Pin
FauthD
4:45 20 Oct '05  
GeneralBug and fix in BrowseList Delete_Click Pin
FauthD
4:39 20 Oct '05  
QuestionTextChanged is not working here Pin
FauthD
7:07 18 Oct '05  
Generalpreloading current path/file Pin
FauthD
7:01 18 Oct '05  
GeneralSweet Pin
skitzallykat
16:27 3 Aug '05  
GeneralCaption fix, tooltip, and file validation. Pin
Robert Freeman
5:34 7 Mar '05  
GeneralRe: Caption fix, tooltip, and file validation. Pin
Robert Freeman
7:55 7 Mar '05  
GeneralThe control's icons ... Pin
W. Kleinschmit
3:31 2 Feb '05  
GeneralRe: The control's icons ... Pin
Todd Davis
3:35 2 Feb '05  
GeneralThe resizing bug ... Pin
W. Kleinschmit
2:48 2 Feb '05  
GeneralFew questions Pin
sdcougar
10:03 13 Jan '05  
GeneralRe: Few questions Pin
Todd Davis
10:11 13 Jan '05  
GeneralRe: Few questions Pin
sdcougar
10:50 13 Jan '05  
GeneralRe: Few questions Pin
sdcougar
16:15 13 Jan '05  
GeneralDragDrop registration failed Pin
zoomba
10:55 5 Nov '04  


Last Updated 31 Jan 2005 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009