views:

25

answers:

3

Hi, I need help creating a .dll file from a custom control so that it can be used on other projects. This is the first time I am doing this, and I couldn't find much help via google so help would be much appreciated.

I have this code and I know I have to compile it as a class project, but I really don't know how, so I'd appreciate it if someone can guide me how I would do that.

+1  A: 

All you have to do is create a new Class Library project, then paste your code into a class file. Then compile.

You can reference the resulting DLL from other projects.

Here's a tutorial.

Jon B
I thought it would be that, but when I tried I got a bunch of errors. It works fine though now, thanks.
david
+1  A: 

I think it's simply a matter of changing your output type to Class Library in the Application tab of your project's properties.

Jens
A: 

Start a new Windows Forms project. Project + Add Reference, select Microsoft.VisualBasic. Project + Add New Item, select Class. Delete what's there then paste the code. Compile. Drop the new control from the top of the toolbox onto the form.

There's a bug in the code, you'll get the drives displayed twice when you press F5. Alter the code and make it look like this:

    public FileExplorer() {
        this.BeforeExpand += customBeforeExpand;
        // CreateTree(this);    // <== delete this line
    }

    protected override void OnHandleCreated(EventArgs e) {
        base.OnHandleCreated(e);
        if (!DesignMode) CreateTree(this);
    }
Hans Passant
Thanks, that worked! :)
david
@david - please read this: http://blog.stackoverflow.com/2010/10/vote-early-vote-often/
Hans Passant