C#
  Home arrow C# arrow Page 3 - 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  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
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 - Filtering Control Class Members


    (Page 3 of 7 )

    From time to time, you might want to hide a control event or property from the design-time view of the developer.

    For example, every control provides a Text property, because every control inherits from the base System.Windows.Forms.Control class.

    However, not all controls can effectively use the Text property. For example, the TreeView control doesn't actually use its Text property - you can set it in code, but it won't modify the user interface. For this reason, the Text property is not displayed in the Properties window.

    If you are defining a property, you can use the Browsable attribute to keep it from appearing in the Properties window. However, consider the TreeView control, which provides a Nodes collection.

    The DirectoryTree inherits the Nodes property, and allows it to be modified at design-time, even though the list of nodes is built automatically at runtime based on the Drive property.

    This conflict means that there are really two ways the developer can alter the Nodes collection-indirectly through the Driver property, or directly through the Nodes collection, which is sure to lead to a great deal of confusion.

    Unfortunately, because the TreeView.Nodes property is not overridable, you can't use the Browsable attribute. However, you can create a custom designer that ensures it won't appear at design-time.

    To use filtering with the DirectoryTree, create a custom designer class that derives from ControlDesigner:

    public class DirectoryTreeDesigner : ControlDesigner
    {

    protected override void PostFilterProperties(
    System.Collections.IDictionary properties)
    {
    properties.Remove("Nodes");
    }

    }


    This designer overrides the PostFilterProperties() method, and removes the Nodes property from the properties collection.

    The next step is to link the custom designer to the DirectoryTree control. To do this, use the Designer attribute, and specify the appropriate designer type.

    [DefaultEvent("DirectorySelected"),
    DefaultProperty("Drive"),
    Designer(typeof(DirectoryTreeDesigner))]
    public class DirectoryTree : TreeView
    {


    Note that the Nodes property is still accessible in code. This allows clients to perform other useful tasks (like enumerating through the collection of nodes) at their discretion. However, it can't be designed, and it won't be serialized.

    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 2 hosted by Hostway