Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 335
Behzad Avatar asked Oct 20 '22 11:10

Behzad


1 Answers

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.

like image 79
Louis Somers Avatar answered Nov 15 '22 04:11

Louis Somers