Exportar (0) Imprimir
Expandir todo
Expandir Minimizar
Este artículo proviene de un motor de traducción automática. Mueva el puntero sobre las frases del artículo para ver el texto original. Más información.
Traducción
Original

ToolboxItemFilterType (Enumeración)

Define identificadores que indican el tipo del filtro utilizado por un ToolboxItemFilterAttribute.

Espacio de nombres:  System.ComponentModel
Ensamblado:  System (en System.dll)

public enum ToolboxItemFilterType

Nombre de miembroDescripción
AllowIndica que la cadena de filtro de un elemento del cuadro de herramientas está permitida, pero no es necesario.
CustomIndica que se requiere procesamiento personalizado para determinar si se debe utilizar una cadena de filtro de elemento del cuadro de herramientas.

Este tipo de ToolboxItemFilterType se especifica normalmente en una clase de diseñador raíz para indicar que el diseñador desea aceptar o rechazar un elemento de cuadro de herramientas mediante código. El diseñador debe implementar el método GetToolSupported de la interfaz IToolboxUser.

PreventIndica que no está permitida una cadena de filtro de un elemento del cuadro de herramientas.

Si un diseñador y una clase de componente tienen una cadena de filtro y uno de ellos tiene un ToolboxItemFilterType de Prevent, el elemento del cuadro de herramientas no estará disponible.

RequireIndica que debe haber una cadena de filtro de elemento del cuadro de herramientas para que el elemento esté habilitado.

Para que esté habilitado un elemento del cuadro de herramientas con un tipo de filtro Require, el diseñador y la clase de componente deben tener una cadena de filtro coincidente. Además, ni el diseñador ni la clase de componente pueden tener un ToolboxItemFilterType de Prevent para que esté habilitado el elemento del cuadro de herramientas.

En el ejemplo de código siguiente se muestra cómo se aplica ToolboxItemFilterAttribute.


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

// This example contains an IRootDesigner that implements the IToolboxUser interface.
// This example demonstrates how to enable the GetToolSupported method of an IToolboxUser
// designer in order to disable specific toolbox items, and how to respond to the 
// invocation of a ToolboxItem in the ToolPicked method of an IToolboxUser implementation.
namespace IToolboxUserExample
{
    // This example component class demonstrates the associated IRootDesigner which 
    // implements the IToolboxUser interface. When designer view is invoked, Visual 
    // Studio .NET attempts to display a design mode view for the class at the top 
    // of a code file. This can sometimes fail when the class is one of multiple types 
    // in a code file, and has a DesignerAttribute associating it with an IRootDesigner. 
    // Placing a derived class at the top of the code file solves this problem. A 
    // derived class is not typically needed for this reason, except that placing the 
    // RootDesignedComponent class in another file is not a simple solution for a code 
    // example that is packaged in one segment of code.
    public class RootViewSampleComponent : RootDesignedComponent
	{
	}

	// The following attribute associates the SampleRootDesigner with this example component.
	[DesignerAttribute(typeof(SampleRootDesigner), typeof(IRootDesigner))]
	public class RootDesignedComponent : System.Windows.Forms.Control
	{
	}

    // This example IRootDesigner implements the IToolboxUser interface and provides a 
    // Windows Forms view technology view for its associated component using an internal 
    // Control type.     
    // The following ToolboxItemFilterAttribute enables the GetToolSupported method of this
    // IToolboxUser designer to be queried to check for whether to enable or disable all 
    // ToolboxItems which create any components whose type name begins with "System.Windows.Forms".
    [ToolboxItemFilterAttribute("System.Windows.Forms", ToolboxItemFilterType.Custom)]
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] 
    public class SampleRootDesigner : ParentControlDesigner, IRootDesigner, IToolboxUser
    {
        // This field is a custom Control type named RootDesignerView. This field references
        // a control that is shown in the design mode document window.
        private RootDesignerView view;

        // This string array contains type names of components that should not be added to 
        // the component managed by this designer from the Toolbox.  Any ToolboxItems whose 
        // type name matches a type name in this array will be marked disabled according to  
        // the signal returned by the IToolboxUser.GetToolSupported method of this designer.
        private string[] blockedTypeNames =
        {
            "System.Windows.Forms.ListBox",
            "System.Windows.Forms.GroupBox"
        };

        // IRootDesigner.SupportedTechnologies is a required override for an IRootDesigner.
        // This designer provides a display using the Windows Forms view technology.
        ViewTechnology[] IRootDesigner.SupportedTechnologies 
        {
            get { return new ViewTechnology[] {ViewTechnology.Default}; }
        }

        // This method returns an object that provides the view for this root designer. 
        object IRootDesigner.GetView(ViewTechnology technology) 
        {
            // If the design environment requests a view technology other than Windows 
            // Forms, this method throws an Argument Exception.
            if (technology != ViewTechnology.Default)            
                throw new ArgumentException("An unsupported view technology was requested", 
                "Unsupported view technology.");            

            // Creates the view object if it has not yet been initialized.
            if (view == null)                            
                view = new RootDesignerView(this);          

            return view;
        }

        // This method can signal whether to enable or disable the specified
        // ToolboxItem when the component associated with this designer is selected.
        bool IToolboxUser.GetToolSupported(ToolboxItem tool)
        {       
            // Search the blocked type names array for the type name of the tool
            // for which support for is being tested. Return false to indicate the
            // tool should be disabled when the associated component is selected.
            for( int i=0; i<blockedTypeNames.Length; i++ )
                if( tool.TypeName == blockedTypeNames[i] )
                    return false;

            // Return true to indicate support for the tool, if the type name of the
            // tool is not located in the blockedTypeNames string array.
            return true;
        }

        // This method can perform behavior when the specified tool has been invoked.
        // Invocation of a ToolboxItem typically creates a component or components, 
        // and adds any created components to the associated component.
        void IToolboxUser.ToolPicked(ToolboxItem tool)
        {
        }

        // This control provides a Windows Forms view technology view object that 
        // provides a display for the SampleRootDesigner.
        [DesignerAttribute(typeof(ParentControlDesigner), typeof(IDesigner))]
        internal class RootDesignerView : Control
        {
            // This field stores a reference to a designer.
            private IDesigner m_designer;

            public RootDesignerView(IDesigner designer)
            {
                // Perform basic control initialization.
                m_designer = designer;
                BackColor = Color.Blue;
                Font = new Font(Font.FontFamily.Name, 24.0f);                
            }

            // This method is called to draw the view for the SampleRootDesigner.
            protected override void OnPaint(PaintEventArgs pe)
            {
                base.OnPaint(pe);
                // Draw the name of the component in large letters.
                pe.Graphics.DrawString(m_designer.Component.Site.Name, Font, Brushes.Yellow, ClientRectangle);
            }
        }
    }
}


.NET Framework

Compatible con: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Compatible con: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (no se admite el rol Server Core), Windows Server 2008 R2 (se admite el rol Server Core con SP1 o versiones posteriores; no se admite Itanium)

.NET Framework no admite todas las versiones de todas las plataformas. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

Adiciones de comunidad

AGREGAR
Mostrar:
© 2014 Microsoft