IRootDesigner 接口

定义

提供对根级设计器视图技术的支持。

C#
public interface IRootDesigner : IDisposable, System.ComponentModel.Design.IDesigner
C#
[System.Runtime.InteropServices.ComVisible(true)]
public interface IRootDesigner : IDisposable, System.ComponentModel.Design.IDesigner
C#
public interface IRootDesigner : System.ComponentModel.Design.IDesigner
派生
属性
实现

示例

下面的代码示例演示了与 IRootDesigner 示例用户控件关联的实现。 此 IRootDesigner 实现通过重写 方法在设计器视图中显示后台视图的 GetView 控件。 需要添加对 System.Design 程序集的引用才能编译示例。

若要使用此示例,请将源代码添加到项目,并在设计器视图中显示 RootViewSampleComponent 以显示自定义的根设计器视图。

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

namespace SampleRootDesigner
{	
    // This sample demonstrates how to provide the root designer view, or
    // design mode background view, by overriding IRootDesigner.GetView().

    // This sample component inherits from RootDesignedComponent which 
    // uses the SampleRootDesigner.
    public class RootViewSampleComponent : RootDesignedComponent
    {
        public RootViewSampleComponent()
        {
        }
    }

    // The following attribute associates the SampleRootDesigner designer 
    // with the SampleComponent component.
    [Designer(typeof(SampleRootDesigner), typeof(IRootDesigner))]
    public class RootDesignedComponent : Component
    {
        public RootDesignedComponent()
        {
        }
    }

    public class SampleRootDesigner : ComponentDesigner, IRootDesigner
    {
        // Member field of custom type RootDesignerView, a control that 
        // will be shown in the Forms designer view. This member is 
        // cached to reduce processing needed to recreate the 
        // view control on each call to GetView().
        private RootDesignerView m_view;			

        // This method returns an instance of the view for this root
        // designer. The "view" is the user interface that is presented
        // in a document window for the user to manipulate. 
        object IRootDesigner.GetView(ViewTechnology technology) 
        {
            if (technology != ViewTechnology.Default)
            {
                throw new ArgumentException("Not a supported view technology", "technology");
            }
            if (m_view == null)
            {
                   // Some type of displayable Form or control is required 
                   // for a root designer that overrides GetView(). In this 
                   // example, a Control of type RootDesignerView is used.
                   // Any class that inherits from Control will work.
                m_view = new RootDesignerView(this);
            }
            return m_view;
        }

        // IRootDesigner.SupportedTechnologies is a required override for an
        // IRootDesigner. Default is the view technology used by this designer.  
        ViewTechnology[] IRootDesigner.SupportedTechnologies 
        {
            get
            {
                return new ViewTechnology[] {ViewTechnology.Default};
            }
        }

        // RootDesignerView is a simple control that will be displayed 
        // in the designer window.
        private class RootDesignerView : Control 
        {
            private SampleRootDesigner m_designer;

            public RootDesignerView(SampleRootDesigner designer)
            {
                m_designer = designer;
                BackColor = Color.Blue;
                Font = new Font(Font.FontFamily.Name, 24.0f);
            }

            protected override void OnPaint(PaintEventArgs pe)
            {
                base.OnPaint(pe);

                // Draws the name of the component in large letters.
                pe.Graphics.DrawString(m_designer.Component.Site.Name, Font, Brushes.Yellow, ClientRectangle);
            }
        }		
    }
}

注解

根设计器是位于当前设计时文档对象层次结构的顶部位置或根的设计器。 根设计器必须实现 IRootDesigner 接口。 根设计器通常在设计器视图模式下管理背景视图,并且通常显示当前设计时项目的基本容器中的控件。

属性

Component

获取此设计器正在设计的基组件。

(继承自 IDesigner)
SupportedTechnologies

获取此设计器可为其显示提供支持的技术集。

Verbs

获取设计器支持的设计时谓词的集合。

(继承自 IDesigner)

方法

Dispose()

执行与释放或重置非托管资源关联的应用程序定义的任务。

(继承自 IDisposable)
DoDefaultAction()

执行此设计器的默认行为。

(继承自 IDesigner)
GetView(ViewTechnology)

获取指定视图技术的视图对象。

Initialize(IComponent)

用指定的组件初始化设计器。

(继承自 IDesigner)

适用于

产品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1