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()

執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。

(繼承來源 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