Search code examples
visual-studiocontrolsrenderingdesign-time

How does visual studio designer display/render any control at design time?


So how does it do that?

Whether you are doing WinForm, WPF or ASP.NET, you can drag any visual control from the toolbox to the design surface. You didn't compile any code, didn't instantiate the class related to the control, but you see that control there, displayed/rendered on the design surface.

What happens under the hood? How Visual Studio do this?


Solution

  • Visual Studio will actually interpret your code on the fly and it will try to run the controls if they don't have any Design-Time version specified. Each control can specify a Design Time control using Attributes. When such an attribute is present, instead of actually rendering the control itself, the design time version of the control is loaded.

    The whole process is rather intricate to answer in a simple Stack Overflow answer, but these documentation pages explain it pretty well:

    These MSDN back issues are now .chm help files. You will need to unblock them in the file's property page to enable reading the contents after downloading.