C#
  Home arrow C# arrow Page 2 - Custom Controls and Design-Time Support: P...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

Custom Controls and Design-Time Support: Part 2/2
By: Wrox Team
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 17
    2003-01-13

    Table of Contents:
  • Custom Controls and Design-Time Support: Part 2/2
  • The DirectoryTree
  • Filtering Control Class Members
  • Designer Verbs
  • UITypeEditors
  • Custom UITypeEditors
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Custom Controls and Design-Time Support: Part 2/2 - The DirectoryTree


    (Page 2 of 7 )

    In the first article in this series, we considered a DirectoryTree control that automatically displays a hierarchical list of directories in the drive indicated by the Drive property.

    This control introduces several advantages over performing the same sort of work manually:
    • Though the DirectoryTree is based on a TreeView control, it isolates the client programmer from TreeView-specific details like nodes. It even raises a higher lever DirectorySelected event.
    • Directory entries are added automatically as needed when nodes are expanded, ensuring that the control performs equal well for small drives as for drives that have tens of thousands of subdirectories.
    • All the details are completely encapsulated. All the client programmer needs to worry about is setting the Drive property and handling the DirectorySelected event.
    Of course, this control had its own quirks as well.

    Notably, if you set the Drive property at design time, you ended up with two copies of the root directory at run time-one created dynamically by the control, and one from the nodes that Visual Studio .NET has automatically serialized.

    Last article, we demonstrated a simple workaround, but a more elegant solution is possible with a custom control designers.

    Before continuing any further, we need to import three additional namespaces, the bottom three shown below. These give us access to key pieces of .NET design-time support.

    using System;
    using System.IO;
    using System.Windows.Forms;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Windows.Forms.Design;
    using System.Drawing.Design;


    Control Designers

    One problem with traditional ActiveX control development is that the control's design-time behavior must be coded alongside the control's runtime behavior.

    In the world of .NET, this problem is neatly sidestepped by a new feature: control designers. Control designers are exclusively concerned with providing the design-time behavior for a control.

    The .NET framework provides a basic control designer with the ControlDesigner class in the System.Windows.Forms.Design namespace. It also provides derived classes that add support for child control containment and scrolling.

    Controls can use the default designer (as we've done so far with the DirectoryTree control), or they can derive their own custom designers.

    So why would you create your own designer?
    • To add special designer tools, like context menu options.
    • To remove inappropriate events or properties from view (or add design-time only events or properties).
    • To add support for controls that contain other controls (like the toolbar) or controls with special needs (like menus).

    More C# Articles
    More By Wrox Team


     

    C# ARTICLES

    - Introduction to Objects and Classes in C#, P...
    - Visual C#.NET, Part 1: Introduction to Progr...
    - C# - An Introduction
    - Hotmail Exposed: Access Hotmail using C#
    - Razor Sharp C#
    - Introduction to Objects and Classes in C#
    - Making Your Code CLS Compliant
    - Programming with MySQL and .NET Technologies
    - Socket Programming in C# - Part II
    - Socket Programming in C# - Part I
    - Creational Patterns in C#
    - Type Conversions
    - Creating Custom Delegates and Events in C#
    - Inheritance and Polymorphism
    - Understanding Properties in C#






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT