NestedContainer NestedContainer NestedContainer NestedContainer Class

定義

提供 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
繼承
NestedContainerNestedContainerNestedContainerNestedContainer
實作

備註

類別是INestedContainer介面的簡單執行, 它會定義邏輯上包含零個或多個其他元件且由父元件所擁有的元件。 NestedContainerThe 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(IComponent) NestedContainer(IComponent) NestedContainer(IComponent) NestedContainer(IComponent)

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

屬性

Components Components Components Components

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

(Inherited from Container)
Owner Owner Owner Owner

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

OwnerName OwnerName OwnerName OwnerName

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

方法

Add(IComponent) Add(IComponent) Add(IComponent) Add(IComponent)

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

(Inherited from Container)
Add(IComponent, String) Add(IComponent, String) Add(IComponent, String) Add(IComponent, String)

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

(Inherited from Container)
CreateSite(IComponent, String) CreateSite(IComponent, String) CreateSite(IComponent, String) CreateSite(IComponent, String)

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

Dispose() Dispose() Dispose() Dispose()

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

(Inherited from Container)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

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

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

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

GetType() GetType() GetType() GetType()

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

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(IComponent) Remove(IComponent) Remove(IComponent) Remove(IComponent)

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

(Inherited from Container)
RemoveWithoutUnsiting(IComponent) RemoveWithoutUnsiting(IComponent) RemoveWithoutUnsiting(IComponent) RemoveWithoutUnsiting(IComponent)

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

(Inherited from Container)
ToString() ToString() ToString() ToString()

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

(Inherited from Object)
ValidateName(IComponent, String) ValidateName(IComponent, String) ValidateName(IComponent, String) ValidateName(IComponent, String)

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

(Inherited from Container)

適用於

另請參閱