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

PanelContainerDesigner Class

Note: This class is new in the .NET Framework version 2.0.

Provides design-time support in a visual designer for the Panel control.

Namespace: System.Web.UI.Design.WebControls
Assembly: System.Design (in system.design.dll)

public class PanelContainerDesigner : ContainerControlDesigner
public class PanelContainerDesigner extends ContainerControlDesigner
public class PanelContainerDesigner extends ContainerControlDesigner

The Panel control is used as a container for other controls, especially when controls are generated programmatically.

In a visual designer, when you switch from Source to Design view, the markup source code that describes the associated Panel control is parsed, and a design-time version of the control is created on the design surface. When you switch back to Source view, the design-time control is persisted to markup source code and edited into the markup for the Web page. The PanelContainerDesigner class provides design-time support for Panel controls in a visual designer.

The FrameCaption property gets the caption that appears on the associated Panel control. The FrameStyle property gets the styles of the associated control.

The UsePreviewControl property always returns true, indicating that the designer creates a temporary copy of the associated Panel to generate the design-time markup.

The Initialize method prepares the designer to view, edit, and design the associated Panel control. The AddDesignTimeCssAttributes method sets collection elements to the string representations of various style attributes of the associated control.

The following code example shows how to extend the PanelContainerDesigner class to change the appearance and behavior of controls that are derived from the Panel control at design time.

The example derives the MyPanelContainer class from the Panel control. The example also derives the MyPanelContainerDesigner class from the PanelContainerDesigner class and applies a DesignerAttribute attribute for the MyPanelContainerDesigner on the MyPanelContainer class.

The MyPanelContainerDesigner overrides the following PanelContainerDesigner members:

  • The FrameStyle property to define a design-time border style for the MyPanelContainer control.

  • The FrameCaption property to provide a default caption for the MyPanelContainer control, if none was defined.

  • The Initialize method to throw an ArgumentException exception, if the associated control is not a MyPanelContainer object.

using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;
using System.ComponentModel;
using System.Security.Permissions;

namespace Examples.CS.WebControls.Design
{
    // The MyPanelContainer is a copy of the Panel.
    [AspNetHostingPermission(SecurityAction.Demand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [Designer(typeof(Examples.CS.WebControls.Design.MyPanelContainerDesigner))]
    public class MyPanelContainer : Panel
    {
    } // MyPanelContainer

    // Override members of the PanelContainerDesigner.
    public class MyPanelContainerDesigner : PanelContainerDesigner
    {
        // Provide a design-time caption for the panel.
        public override string FrameCaption 
        {
            get
            {
                // If the FrameCaption is empty, use the panel control ID.
                string localCaption = base.FrameCaption;
                if (localCaption == null || localCaption == "")
                    localCaption = ((Panel)Component).ID.ToString();

                return localCaption;
            }
        } // FrameCaption

        // Provide a design-time border style for the panel.
        public override Style FrameStyle
        {
            get
            {
                Style styleOfFrame = base.FrameStyle;

                // If no border style is defined, define one.
                if (styleOfFrame.BorderStyle == BorderStyle.NotSet ||
                    styleOfFrame.BorderStyle == BorderStyle.None)
                    styleOfFrame.BorderStyle = BorderStyle.Outset;

                return styleOfFrame;
            }
        } // FrameStyle

        // Initialize the designer.
        public override void Initialize(IComponent component)
        {
            // Ensure that only a MyPanelContainer can be created 
            // in this designer.
            if (!(component is MyPanelContainer))
                throw new ArgumentException();
            
            base.Initialize(component);

        } // Initialize
    } // MyPanelContainerDesigner
} // Examples.CS.WebControls.Design

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 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.