Behzad
Behzad

Reputation: 3580

What is the "Control.Site" Property?

In Windows Forms applications, controls in the System.Windows.Forms library have a property named Site. What is this property’s job in Controls?

Upvotes: 6

Views: 1744

Answers (2)

Louis Somers
Louis Somers

Reputation: 2964

The Site property is inherited from Component, and is very much like the Parent property of a Control.

The main difference between Parent and Site is that the value of Parent can only be a Control, while Site can have a non-visual container assigned to it.

The Component base-class is used for those non-visual tools in the Winforms designer toolbox. For example the System.Windows.Forms.Timer which can be dragged onto a Form. The PropertyGrid can be used to set its properties and assign event-handlers, all from the designer without writing a line of code.

The idea behind the System.ComponentModel classes is to provide an API for Software libraries to take advantage of design-time capabilities of an IDE such as Visual Studio. It caters to RAD (Rapid Application Development) concepts where general-purpose or generic components would take advantage of the API. For example to expose extra information about a property in the bottom section of the property-grid, or even create complete custom editors.

If you want to dive deeper into the internals you could look at Programming with Components, or if you want a quick overview, I guess Class vs. Component vs. Control may be a good starting point.

Upvotes: 5

Behzad
Behzad

Reputation: 3580

Sites bind a Component to a Container and enable communication between them, as well as provide a way for the container to manage its components. Sites can also serve as a repository for container-specific, per-component information, such as the component name. For more information about components, see Programming with Components.

Notes to Implementers

To be a site, a class must implement the ISite interface.

Reference: https://msdn.microsoft.com/en-us/library/system.componentmodel.isite.aspx

Upvotes: 0

Related Questions