NestedContainer 類別


提供 INestedContainer 介面的簡單實作,讓容器有主控元件。Provides the base implementation for the INestedContainer interface, which enables containers to have an owning component.

public ref class NestedContainer : System::ComponentModel::Container, IDisposable, System::ComponentModel::INestedContainer
public class NestedContainer : System.ComponentModel.Container, IDisposable, System.ComponentModel.INestedContainer
type NestedContainer = class
    inherit Container
    interface INestedContainer
    interface IContainer
    interface IDisposable
Public Class NestedContainer
Inherits Container
Implements IDisposable, INestedContainer


NestedContainer 類別是 INestedContainer 介面的簡單執行,它會定義邏輯上包含零個或多個其他元件且由父元件所擁有的元件。The NestedContainer class is a simple implementation of the INestedContainer interface, which defines a component that logically contains zero or more other components and is owned by a parent component. 嵌套容器的行為與標準 Container 有數種不同,包括下列各項:The behavior of nested containers differs from a standard Container in a number of ways, including the following:

  • 網站特性(例如 DesignModeGetService)會透過主控元件的網站來路由傳送。Site characteristics such as DesignMode and GetService are routed through the owning component's site.

  • 網站的 Name 屬性是限定名稱,其中包含擁有元件的名稱,後面接著句號(.)和子元件的名稱。The site's Name property is a qualified name that includes the owning component's name followed by a period (.) and the child component's name.

  • GetService 提供 INestedContainer 服務的支援。GetService provides support for the INestedContainer as a service.

  • 處置主控元件時,也會處置容器。When the owning component is disposed, the container is disposed as well.

此外,設計工具會以不同的方式來處理嵌套的容器。In addition, designers treat nested containers differently. 設計工具主機只對一個容器感興趣,也就是與主機相關聯的一個。A designer host is only interested in one container - the one associated with the host. 因此,當元件加入或從嵌套容器中移除時,不會引發元件新增和移除事件。Therefore, component add and remove events are not raised when a component is added to or removed from a nested container. 不過,由於服務會流向已嵌套的容器,因此當變更了嵌套容器中的元件時,就會引發元件變更事件。However, because services flow through to the nested container, component change events are raised when a component in a nested container is changed.

事件追蹤中的這個差異也會影響與序列化緊密相關的復原功能。This disparity in event tracking also impacts undo functionality, which is closely tied to serialization. 標準的復原引擎會使用 IReferenceService 來追蹤對元件所做的變更。The standard undo engine uses IReferenceService to track changes made to components. 如果復原引擎無法透過參考服務識別元件的名稱,引擎就會忽略該元件的任何變更。If the undo engine cannot identify a name for a component through the reference service, the engine will ignore any changes for that component. 只有當包含的元件在其擁有者中公開為具有相同名稱的公用唯讀屬性時,此服務才會自動辨識其變更。This service automatically recognizes changes to contained components only if they are exposed as public read-only properties of the same name in their owners. 否則,開發人員必須將元件變更事件傳遞給擁有者。Otherwise, the developer must pass component change events up to the owner. 例如,如果嵌套元件的 Text 屬性是在其主控元件上 resurfaced 為 Address 屬性,則當 Text 屬性變更時,必須以程式設計方式對對應的 Address 屬性進行屬性變更,否則將不會由復原來追蹤變更。For example, if a nested component's Text property is resurfaced on its owning component as an Address property, when the Text property is changed, a property change must be programmatically made for the corresponding Address property or else that change will not be tracked by undo.



初始化 NestedContainer 類別的新執行個體。Initializes a new instance of the NestedContainer class.



取得 Container 中的所有元件。Gets all the components in the Container.

(繼承來源 Container)

取得這個巢狀容器的主控元件。Gets the owning component for this nested container.


取得主控元件的名稱。Gets the name of the owning component.



將指定的 Component 加入至 ContainerAdds the specified Component to the Container. 元件未命名。The component is unnamed.

(繼承來源 Container)
Add(IComponent, String)

將指定的 Component 加入 Container,並指派名稱給它。Adds the specified Component to the Container and assigns it a name.

(繼承來源 Container)
CreateSite(IComponent, String)

為容器內的元件建立站台。Creates a site for the component within the container.


釋放 Container 所使用的所有資源。Releases all resources used by the Container.

(繼承來源 Container)

釋放巢狀容器所使用的資源。Releases the resources used by the nested container.


判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)

取得指定型別的服務物件 (如果有的話)。Gets the service object of the specified type, if it is available.


取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)

Container 移除元件。Removes a component from the Container.

(繼承來源 Container)

Container 移除元件,而不必將 Site 設定為 nullRemoves a component from the Container without setting Site to null.

(繼承來源 Container)

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
ValidateName(IComponent, String)

判斷元件名稱對這個容器而言是否唯一。Determines whether the component name is unique for this container.

(繼承來源 Container)