Export (0) Print
Expand All

CategoryNameCollection Class

Represents a collection of category name strings.

Namespace: System.Drawing.Design
Assembly: System.Drawing (in system.drawing.dll)

public sealed class CategoryNameCollection : ReadOnlyCollectionBase
public final class CategoryNameCollection extends ReadOnlyCollectionBase
public final class CategoryNameCollection extends ReadOnlyCollectionBase
Not applicable.

This collection is used to store collections of toolbox category names.

The following code example attempts to retrieve the IToolboxService when the control is sited in design mode. If the IToolboxService is retrieved, the code gets the names of each toolbox category and draws each name on the surface of the control.

using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Data;
using System.Windows.Forms;

namespace ToolboxCategoryNamesControl
{    
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] 
	public class ToolboxCategoryNamesControl : System.Windows.Forms.UserControl
	{		
        private System.Drawing.Design.IToolboxService toolboxService;
        private System.Drawing.Design.CategoryNameCollection categoryNames;

		public ToolboxCategoryNamesControl()
		{
            this.BackColor = System.Drawing.Color.Beige;
            this.Name = "Category Names Display Control";
            this.Size = new System.Drawing.Size(264, 200);
		}

        // Obtain or reset IToolboxService reference on each siting of control.
        public override System.ComponentModel.ISite Site
        {
            get
            {
                return base.Site;
            }
            set
            {     
                base.Site = value;

                // If the component was sited, attempt to obtain 
                // an IToolboxService instance.
                if( base.Site != null )
                {
                    toolboxService = (IToolboxService)this.GetService(typeof(IToolboxService));
                    // If an IToolboxService was located, update the category list.
                    if( toolboxService != null )
                        categoryNames = toolboxService.CategoryNames;                   
                }
                else
                    toolboxService = null;
            }
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {            
            if( categoryNames != null )
            {
                e.Graphics.DrawString("IToolboxService category names list:", new Font("Arial", 9), Brushes.Black, 10, 10);
                // categoryNames is a CategoryNameCollection obtained from 
                // the IToolboxService. CategoryNameCollection is a read-only 
                // string collection.                                
                
                // Output each category name in the CategoryNameCollection.                                                
                for( int i=0; i< categoryNames.Count; i++ )                                    
                    e.Graphics.DrawString(categoryNames[i], new Font("Arial", 8), Brushes.Black, 10, 24+(10*i));                
            }            
        }
	}    
}

System.Object
   System.Collections.ReadOnlyCollectionBase
    System.Drawing.Design.CategoryNameCollection

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft