Groups | Blog | Home
all groups > dotnet windows forms designtime > july 2007 >

dotnet windows forms designtime : Where does the designer code come from?


schneider
7/9/2007 2:00:39 PM
How does the designer determine what code is used in the form designer code?

For example 1, when you drag a control (using the object name?):

private System.Windows.Forms.TextBox txtUserName;

this.txtUserName = new System.Windows.Forms.TextBox();


Thanks,
Schneider

OD
7/15/2007 2:28:42 PM
[quoted text, click to view]

When you drag a component onto the designer surface, VS is knowing the
class, then using reflection, it can get the list of public properties
and events. As all components must implement IComponent (providing
functionnality required by all components) and must inherit from
Control, it is easy to generate the "new" code and to manage other
common component behaviors.

Nothing really magic, just object programming :-)

--


OD___
www.e-naxos.com

schneider
7/16/2007 9:54:48 PM
Yes, I guess I should have said "What .NET objects are used to generate the
code?" I want to alter the behavior.

Thanks,
Schneider


[quoted text, click to view]

schneider
7/17/2007 9:35:35 AM
I'm looking for what classes are used in creating the code.

Some X object/s must look at the component and decide what to generate code
for and what to ignore or decide where the code should be or look like.

There is also something that decides to put code into different
methods/regions, and creat comments like below.
I'm looking for info on how all this is done.

Thanks,
Schneider
#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent() {


[quoted text, click to view]

OD
7/17/2007 2:23:20 PM
[quoted text, click to view]

The way code is generated mostly depends on the component itself.
For example, attributes such as Description, Browsable, default values,
default event, etc, are used in component source code and help VS to
display properties, to generate default event when you double-click the
component under design, etc.. Changing this attributes will change the
component behavior under design.

But can you be more precise about what you're wanting to do, give a
little sample if possible. I'm not sure to fully understand your goal.


--


OD___
www.e-naxos.com

OD
7/17/2007 10:15:21 PM
[quoted text, click to view]

Generating the code is the VS job. There is no framework class for this
task. VS does it just by inspecting the class of the component and
taking into account all the supported attributes.
The way VS generate the code by separating some parts (design), etc, is
the specific job of the application "Visual Studio". Rules are changing
from one version to another (VS 2005 doesnt generate the same code than
VS 2003 for example).
You can write a code that performs the same task just using reflection,
but the way the code is finally "rendered" will be precisely your
application job, as VS does it its own way.

--


OD___
www.e-naxos.com

schneider
9/20/2007 11:08:56 AM
Thanks, that's what I was looking for. Looking to improve the designer code
for my components.

Schneider


[quoted text, click to view]

Sigurbjörn Valdimarsson
9/20/2007 3:48:01 PM
You might want to look at CodeDomSerializer and the
DesignerSerializerAttribute.


[quoted text, click to view]

AddThis Social Bookmark Button