i couldnt find the constructor of the controls like textbox or button neither in the nor in the form.designer.cs. where are they?

Dani AI

Generated

A short clarification that ties the thread together and gives practical next steps.

Control constructors live in the control class itself (framework controls under System.Windows.Forms, custom controls in their own .cs file). The Visual Studio designer does not copy or reimplement those constructor bodies; it writes the code that creates instances and applies properties (typically inside the generated InitializeComponent method of the .Designer.cs partial file). That separation comes from C# partial classes and the designer's code generator, so the initialization code can appear in different regions or sections of the generated file.

Quick ways to find and inspect constructors and instantiation sites:

  • Open the form's .Designer.cs and search for InitializeComponent or the control variable name to locate where the designer calls new.
  • Use Go To Definition or the Object Browser to jump to the control type (for framework types you can view source).
  • If you need the actual constructor implementation for a compiled control, consult the Microsoft reference source or the WinForms repo, or use a decompiler like ILSpy.

A practical caution echoing : avoid editing designer-generated code directly. Put runtime setup after InitializeComponent in the form constructor, or encapsulate startup logic inside the control (override lifecycle methods). Useful references: Reference Source, dotnet/winforms, ILSpy, partial classes.

oh stupid me, i just couldnt see it, the designer inserted my custom control's constructor to another section in the form.designer.cs.

Sorry about it.

Are you playing with designer generated code? That usually makes for a bad day :P

i play every code piece that is generated by visual studio. not even code, but also the configuration files, project files, solution files, inf files ini files what ever is generated by the IDE.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.