Search code examples
c#winformsdesigner

Show dynamically created controls in Windows Forms designer


Is there a way to see controls which are created via code in designer instantly but not only during execution?


Solution

  • The Windows Forms designer only applies properties contained in the automatically generated file "Form1.Designer.cs" (example filename for "Form1"). If you change properties (e.g. text, color, whatever) or create new controls in your own code, i.e. in "Form1.cs", the designer does not show it.

    It is practically impossible because the designer would have to either 1) parse your code or 2) execute it to apply all changes to the controls.

    Option 1 does not work because expression evaluation only works when running the code... Which leads us to option 2: Letting the designer running your code to find out dynamically added properties? First of all, automatically running untrusted code is not what you want. Second, there must be a reason that you do these changes dynamically instead of statically in the designer, so showing dynamic changes as WYSIWYG does not even make sense.