Is there a way to see controls which are created via code in designer instantly but not only during execution?
-
Which designer? WPF? Windows Forms? – AndiDog Feb 19 '12 at 14:11
-
Normally you can see them directly in the designer. Which kind of controls do you mean? Please elaborate. – AndiDog Feb 19 '12 at 14:16
-
Labels, textboxes, groupboxes. I see none of them. – Shibli Feb 19 '12 at 14:19
-
Oh, I think I got the question wrong... You can't see controls that are created at runtime and which are not in the designer-created file. How should that be possible? – AndiDog Feb 19 '12 at 14:23
-
For example, I changed the name of the form in the constructor but that was not reflected to designer as it still shows the name as Form1. – Shibli Feb 19 '12 at 14:27
2 Answers
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.

- 68,631
- 21
- 159
- 205
The designer can only display controls that exist at design time or show example controls for databound controls. If you think about code that would dynamically at runtime create a textbox or label based on a variable, how would the designer know which one to display in design mode?
If you have specific logic for how you want your dynamically created controls to display in design mode, you would have to create a custom control and implement the design time drawing code. This is mentioned under the Custom Design Experience heading here: http://msdn.microsoft.com/en-us/library/ms171725.aspx

- 1,339
- 8
- 12