Search code examples
c#winformsservice

C# when in Control's life cycle is Site (ISite) not null?


I have a form

MyForm : System.Windows.Forms.Form {}

and I need to call

Site.GetService(..)

before user starts using this form.

But it's null in constructor and all loading events I've tried to override. When is the Site not null, please?


Solution

  • By default, IComponent.Site is set only in the Visual Studio designer. It is used for design-time services within the IDE such as naming the component. Here is an article that talks about how sites are used: Design-Time Integration—Hosts, Containers, and Sites.