Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

IDictionaryService Interface

Provides a basic, component site-specific, key-value pair dictionary through a service that a designer can use to store user-defined data.

Namespace: System.ComponentModel.Design
Assembly: System (in system.dll)

public interface IDictionaryService
public interface IDictionaryService
public interface IDictionaryService
Not applicable.

This service provides a simple interface to set, retrieve, and look up objects with associated keys.

The following example control and designer use the IDictionaryService to share data through its site-specific key-value pair dictionary.

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

namespace IDictionaryServiceControl
{
    // This example control works with the IDictionaryServiceDesigner to demonstrate
    // using the IDictionaryService for storing data provided by a designer, and
    // accessing it from a control. The IDictionaryService provides a Site-specific 
    // key-based dictionary. An IDictionaryServiceDesigner sets an ArrayList of strings 
    // to the dictionary with a "DesignerData" key, and its contents are accessed and
    // displayed once the Update box is clicked at design time.
    [DesignerAttribute(typeof(IDictionaryServiceDesigner), typeof(IDesigner))]
    public class IDictionaryServiceControl : System.Windows.Forms.UserControl
    {
        public ArrayList al;

        public IDictionaryServiceControl()
        {            
            // Initializes the example control.
            al = new ArrayList();
            this.Size = new Size(344, 88);
            this.BackColor = Color.White;
        }

        // Draws the instructions and user interface, and any strings contained 
        // in a local ArrayList.
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if( this.DesignMode )
            {
                e.Graphics.DrawString("IDictionaryServiceDesigner Control", new Font(FontFamily.GenericMonospace, 9), new SolidBrush(Color.Blue), 5, 4);                         
                e.Graphics.DrawString("Click the Update box to update display strings", new Font(FontFamily.GenericMonospace, 8), new SolidBrush(Color.DarkGreen), 5, 17);
                e.Graphics.DrawString("from the IDictionaryService.", new Font(FontFamily.GenericMonospace, 8), new SolidBrush(Color.DarkGreen), 5, 29);                 
                
                e.Graphics.FillRectangle(new SolidBrush(Color.Beige), 270, 7, 60, 10);
                e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black), 1), 270, 7, 60, 10);
                e.Graphics.DrawString("Update", new Font(FontFamily.GenericMonospace, 7), new SolidBrush(Color.Black), 282, 7);

                for( int i=0; i<al.Count; i++ )            
                    e.Graphics.DrawString((string)al[i], new Font(FontFamily.GenericMonospace, 8), new SolidBrush(Color.Black), 5, 44+(i*12));            
            }
        }

        // On mouse down, this method attempts to access the IDictionaryService and 
        // obtain an ArrayList with a key of "DesignerData" in the dictionary.
        // If successful, this ArrayList is set to the local ArrayList.
        protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            // Attempts to obtain the IDictionaryService using the Control.GetService method.
            IDictionaryService ds = (IDictionaryService)GetService(typeof(IDictionaryService));
            // If the service was obtained...
            if( ds != null )
            {
                // Attempts to retrieve a list with a key of "DesignerData".
                ArrayList list = (ArrayList)ds.GetValue( "DesignerData" );
                // If the list exists, sets the list obtained by the 
                // IDictionaryService to the local list.
                if( list != null )
                    this.al = list;
                this.Refresh();
            }
        }
    }

    // This designer uses the IDictionaryService to store an ArrayList of
    // information strings that the associated control can access and 
    // display. The IDictionaryService creates a new dictionary for each Site.
    public class IDictionaryServiceDesigner : System.Windows.Forms.Design.ControlDesigner
    {
        public IDictionaryServiceDesigner()
        {
        }

        // On designer initialization, this method attempts to obtain 
        // the IDictionaryService, and populates an ArrayList
        // associated with a "DesignerData" key in the dictionary with 
        // designer- and control-related information strings.
        public override void Initialize(System.ComponentModel.IComponent component)
        {
            base.Initialize(component);            
            IDictionaryService ds = (IDictionaryService)component.Site.GetService(typeof(IDictionaryService));
            if( ds != null )
            {
                // If the dictionary service does not contain a 
                // DesignerData key, adds an ArrayList for that key.
                if( ds.GetValue( "DesignerData" ) == null )           
                {
                    ds.SetValue( "DesignerData", new ArrayList() );
                       ds.SetValue( "DesignerData", new ArrayList() );
                }

                // Obtains the ArrayList with the "DesignerData" key 
                // from the dictionary service.
                ArrayList al = (ArrayList)ds.GetValue( "DesignerData" );
                if( al != null )
                {
                    al.Clear();
                    // Populates the array list with designer and 
                    // control information strings.
                    al.Add( "Designer type: "+this.GetType().Name );
                    al.Add( "Control type:  "+this.Control.GetType().Name );
                    al.Add( "Control name:  "+this.Control.Name );                    
                }
            }
        }

        protected override bool GetHitTest(System.Drawing.Point point)
        {
            // Translates the point to client coordinates and passes the 
            // messages to the control while over the click box.
            Point translated = this.Control.PointToClient(point);
            if( translated.X > 269 && translated.X < 331 
                && translated.Y > 7 && translated.Y < 18 )
                return true;
            else
                return base.GetHitTest(point);
        }
    }
}

import System.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.Drawing.*;
import System.Data.*;
import System.Windows.Forms.*;

//  This example control works with the IDictionaryServiceDesigner to 
//  demonstrate using the IDictionaryService for storing data provided
//  by a designer, and accessing it from a control. The IDictionaryService
//  provides a Site-specific key-based dictionary. An IDictionaryServiceDesigner
//  sets an ArrayList of strings to the dictionary with a "DesignerData" key, 
//  and its contents are accessed and displayed once the Update box is clicked at
//  design time.
/** @attribute DesignerAttribute(IDictionaryServiceDesigner.class,
   IDesigner.class)
 */
public class IDictionaryServiceControl extends System.Windows.Forms.UserControl
{
    public ArrayList al;

    public IDictionaryServiceControl()
    {
        // Initializes the example control.
        al = new ArrayList();
        this.set_Size(new Size(344, 88));
        this.set_BackColor(Color.get_White());
    } //IDictionaryServiceControl

    // Draws the instructions and user interface, and any strings contained 
    // in a local ArrayList.
    protected void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        if (this.get_DesignMode()) {
            e.get_Graphics().DrawString("IDictionaryServiceDesigner Control",
                new Font(FontFamily.get_GenericMonospace(), 9), 
                new SolidBrush(Color.get_Blue()), 5, 4);
            e.get_Graphics().DrawString("Click the Update box to update"
                + " display strings", new Font(FontFamily.
                get_GenericMonospace(), 8), 
                new SolidBrush(Color.get_DarkGreen()), 5, 17);
            e.get_Graphics().DrawString("from the IDictionaryService.", 
                new Font(FontFamily.get_GenericMonospace(), 8), 
                new SolidBrush(Color.get_DarkGreen()), 5, 29);
            e.get_Graphics().FillRectangle(new SolidBrush(Color.get_Beige()), 
                270, 7, 60, 10);
            e.get_Graphics().DrawRectangle(new Pen(new 
                SolidBrush(Color.get_Black()), 1), 270, 7, 60, 10);
            e.get_Graphics().DrawString("Update", new 
                Font(FontFamily.get_GenericMonospace(), 7), 
                new SolidBrush(Color.get_Black()), 282, 7);

            for (int i = 0; i < al.get_Count(); i++) {
                e.get_Graphics().DrawString((System.String)(al.get_Item(i)),
                    new Font(FontFamily.get_GenericMonospace(), 8), 
                    new SolidBrush(Color.get_Black()), 5, 44 + i * 12);
            }
        }
    } //OnPaint

    // On mouse down, this method attempts to access the IDictionaryService and
    // obtain an ArrayList with a key of "DesignerData" in the dictionary.
    // If successful, this ArrayList is set to the local ArrayList.
    protected void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
    {
        // Attempts to obtain the IDictionaryService using 
        //the Control.GetService method.
        IDictionaryService ds = (IDictionaryService)
            (GetService(IDictionaryService.class.ToType()));

        // If the service was obtained...
        if (ds != null) {
            // Attempts to retrieve a list with a key of "DesignerData".
            ArrayList list = (ArrayList)(ds.GetValue("DesignerData"));

            // If the list exists, sets the list obtained by the 
            // IDictionaryService to the local list.
            if (list != null) {
                this.al = list;
            }
            this.Refresh();
        }
    } //OnMouseDown
} //IDictionaryServiceControl

//  This designer uses the IDictionaryService to store an ArrayList of
//  information strings that the associated control can access and 
//  display. The IDictionaryService creates a new dictionary for each Site.
public class IDictionaryServiceDesigner extends 
    System.Windows.Forms.Design.ControlDesigner
{
    public IDictionaryServiceDesigner()
    {
    } //IDictionaryServiceDesigner

    // On designer initialization, this method attempts to obtain 
    // the IDictionaryService, and populates an ArrayList
    // associated with a "DesignerData" key in the dictionary with 
    // designer- and control-related information strings.
    public void Initialize(System.ComponentModel.IComponent component)
    {
        super.Initialize(component);

        IDictionaryService ds = (IDictionaryService)(component.get_Site().
            GetService(IDictionaryService.class.ToType()));

        if (ds != null) {
            // If the dictionary service does not contain a 
            // DesignerData key, adds an ArrayList for that key.
            if (ds.GetValue("DesignerData") == null) {
                ds.SetValue("DesignerData", new ArrayList());
                ds.SetValue("DesignerData", new ArrayList());
            }
            // Obtains the ArrayList with the "DesignerData" key 
            // from the dictionary service.
            ArrayList al = (ArrayList)(ds.GetValue("DesignerData"));

            if (al != null) {
                al.Clear();

                // Populates the array list with designer and 
                // control information strings.
                al.Add("Designer type: " + this.GetType().get_Name());
                al.Add("Control type:  " 
                    + this.get_Control().GetType().get_Name());
                al.Add("Control name:  " + this.get_Control().get_Name());
            }
        }
    } //Initialize

    protected boolean GetHitTest(System.Drawing.Point point)
    {
        // Translates the point to client coordinates and passes the 
        // messages to the control while over the click box.
        Point translated = this.get_Control().PointToClient(point);

        if (translated.get_X() > 269 && translated.get_X() < 331 && 
            translated.get_Y() > 7 && translated.get_Y() < 18) {
            return true;
        }
        else {
            return super.GetHitTest(point);
        }
    } //GetHitTest
} //IDictionaryServiceDesigner

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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.