Adding Your Custom Controls to Other Projects

function OpenWin(url, w, h) { if(!w) w = 400; if(!h) h = 300; window.open(url, "_new", "width=" + w + ",height=" + h + ",menubar=no,toobar=no,scrollbars=yes", true); } function Print() { window.focus(); if(window.print) { window.print(); window.setTimeout('window.close();',5000); } }
Team-Fly    

Special Edition Using Microsoft® Visual Basic® .NET
By Brian Siler, Jeff Spotts
Table of Contents
Chapter 16.  Creating Your Own Windows Controls


When you built your control during the development process, a Dynamic Link Library (DLL) file named MySampleControls.dll was created in the bin folder under the MySampleControls project folder. The DLL file contains all the instructions necessary for other projects to utilize the custom NameText control that you created (as well as any other custom controls that you may have added to the MySampleControls project).

If you have made any changes to the control project since the last time you built it, be sure to build it again so there is a fresh copy of the DLL file available.

Adding Custom Controls to the Toolbox

You will probably want to use custom controls that you have already designed, tested, debugged, and built in other Visual Basic .NET projects. You could, of course, just add the Windows Control Library project(s) to each Visual Basic .NET solution you create. This is not good practice, however, as you will have multiple copies of the control's source spread around; if you fix an error or enhance the control in one copy, you must repeat the process in other copies or you will have mismatched versions of the same control floating around.

A better way to include the functionality of new controls and control libraries is to add a reference to the controls' DLLs to each project in which you want to use the controls. To demonstrate how to add custom control references to new projects, follow these steps (which assume that you have completed the NameText sample project earlier in this chapter):

  1. Start a new Windows Application project. Give it any name you desire.

  2. With the Designer window for your project's main form visible, click the Toolbox tab to display the Toolbox.

  3. Right-click anywhere in the Windows Forms area of the Toolbox (right-clicking an existing control is fine), then choose Customize Toolbox from the pop-up menu. The Customize Toolbox dialog box appears, as shown in Figure 16.12.

    Figure 16.12. The Customize Toolbox dialog box allows you to manage the controls available to your programs.

    graphics/16fig12.gif

  4. In the Customize Toolbox dialog box, click the .NET Framework Components tab to display the components that are available through .NET.

  5. Click the Browse button and browse to the filename and location of your compiled DLL file, then click the Open button. (For the purposes of the sample NameText control created earlier in this chapter, look for the file MySampleControls.dll, which is stored in the bin folder under your MySampleControls project folder.)

  6. Your DLL and the individual custom control(s) contained in it are added to the .NET Framework Components tab of the Customize Toolbox dialog box, as illustrated in Figure 16.13.

    Figure 16.13. Custom-built controls contained in DLL files can be added to the Toolbox via the Customize Toolbox dialog box.

    graphics/16fig13.gif

  7. Make sure that the desired controls are checked, then click OK to close the Customize Toolbox dialog box.

  8. Scroll the Toolbox until you see the custom control(s) you just added, as shown in Figure 16.14. You can now add a NameText control to this new Windows Application project.

    Figure 16.14. After customizing the Toolbox, the newly added custom controls are available for use in new projects.

    graphics/16fig14.gif

After you have added a new custom control to your project, you may want to examine the References folder in the Solution Explorer to see that a reference to the custom control's library has been added to your project as well.

Tip

Once you have added your new custom controls to the Toolbox, they are available to all projects.



    Team-Fly    
    Top
     



    Special Edition Using Visual Basic. NET
    Special Edition Using Visual Basic.NET
    ISBN: 078972572X
    EAN: 2147483647
    Year: 2001
    Pages: 198

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net