By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,997 Members | 1,470 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,997 IT Pros & Developers. It's quick & easy.

Manually creating a form

P: n/a
Hi there,

I'd like to re-create a form given only its resource file. I was going to
simply read the resource file and re-create the "Form" object and all its
controls as found in this file (applying all properties in the file and
relying on the default properties for those not found). After looking at
"InitializeComponent()" however (which is what I'm really trying to
re-produce here), can somone explain why this function does the following:

1) Manually sets the "Name" property for each control which overwrites the
same property found in the resource file itself (athough the names are the
same - it should rely solely on the resource file however). E.g., I see this
in code *after* reading the same value from the resource file:

this.MyButton.Name = "MyButtonName";

2) Occasionally adds other properties in code such as:

this.MyButton.UseVisualStylebackColor = true
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
etc.

How is anyone supposed to to know to apply the above properties and possibly
others when all you have is the resource file to work with? Moreover, is
there a more appropriate (official) way to generate a form from its resource
file (manually doing it is tedious and error prone). Thanks.
Jun 20 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Those code is generated when you drag a control on a form or set its
properties. Today VB.NET has a free tool called VB.NET 2005 Express so why
worry to reproduce the form from the resource file?

chanmm
"Jake Forson" <no_spam@_nospam.com> wrote in message
news:Ou**************@TK2MSFTNGP05.phx.gbl...
Hi there,

I'd like to re-create a form given only its resource file. I was going to
simply read the resource file and re-create the "Form" object and all its
controls as found in this file (applying all properties in the file and
relying on the default properties for those not found). After looking at
"InitializeComponent()" however (which is what I'm really trying to
re-produce here), can somone explain why this function does the following:

1) Manually sets the "Name" property for each control which overwrites the
same property found in the resource file itself (athough the names are the
same - it should rely solely on the resource file however). E.g., I see
this in code *after* reading the same value from the resource file:

this.MyButton.Name = "MyButtonName";

2) Occasionally adds other properties in code such as:

this.MyButton.UseVisualStylebackColor = true
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
etc.

How is anyone supposed to to know to apply the above properties and
possibly others when all you have is the resource file to work with?
Moreover, is there a more appropriate (official) way to generate a form
from its resource file (manually doing it is tedious and error prone).
Thanks.

Jun 20 '06 #2

P: n/a
> Those code is generated when you drag a control on a form or set its
properties. Today VB.NET has a free tool called VB.NET 2005 Express so why
worry to reproduce the form from the resource file?


My application requires it.
Jun 20 '06 #3

P: n/a
I have a somewhat similar requirement, but I never understood that resource
files to be a full representation of a form's design. I thought they were
just used for localization. Is there some documentation section I missed
and should read?

"Jake Forson" <no_spam@_nospam.com> wrote in message
news:Ou**************@TK2MSFTNGP05.phx.gbl...
Hi there,

I'd like to re-create a form given only its resource file. I was going to
simply read the resource file and re-create the "Form" object and all its
controls as found in this file (applying all properties in the file and
relying on the default properties for those not found). After looking at
"InitializeComponent()" however (which is what I'm really trying to
re-produce here), can somone explain why this function does the following:

1) Manually sets the "Name" property for each control which overwrites the
same property found in the resource file itself (athough the names are the
same - it should rely solely on the resource file however). E.g., I see
this in code *after* reading the same value from the resource file:

this.MyButton.Name = "MyButtonName";

2) Occasionally adds other properties in code such as:

this.MyButton.UseVisualStylebackColor = true
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
etc.

How is anyone supposed to to know to apply the above properties and
possibly others when all you have is the resource file to work with?
Moreover, is there a more appropriate (official) way to generate a form
from its resource file (manually doing it is tedious and error prone).
Thanks.

Jun 20 '06 #4

P: n/a
>I have a somewhat similar requirement, but I never understood that resource
files to be a full representation of a form's design. I thought they were
just used for localization. Is there some documentation section I missed
and should read?


They are used just for localization. You can re-create the entire form from
the ".resx" files however once your app is localized. This won't include
anything extra however that either "InitializeComponent()" adds or the
developer himself (immediately after the call to "InitializeComponent()"
normally). This is fine for my own purposes (not sure about yours - you may
want to elaborate) but I don't understand why "InitializeComponent()" needs
to add any extraneous code at all (as mentioned in my last post). It seems
to me that once a form is localized, you should be able to re-create it
based purely on what's in the resource files alone (not including any
non-localized customization by the developer as noted).
Jun 21 '06 #5

P: n/a

"Jake Forson" <no_spam@_nospam.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
It seems to me that once a form is localized, you should be able to
re-create it based purely on what's in the resource files alone (not
including any non-localized customization by the developer as noted).


I don't follow this logic. The express purpose of the resx file is not to
provide a full description of the form's design but rather to provide
description of those aspects of a form's design that could change between
languages, etc. I don't understand how you can be critical of something for
being incomplete in a purpose for which it is not intended (for "not
including any non-localized customization").

I'm not meaning to argue for its own sake, I truly just am puzzled by your
statements.

Can I use a semi tractor/trailer to go get McDonald's? Yes, with some
special effort and some limitations. Should I criticize a semi
tractor/trailer for not fitting in the drive-in window? No, of course not.
Jun 22 '06 #6

P: n/a
> I don't follow this logic. The express purpose of the resx file is not to
provide a full description of the form's design but rather to provide
description of those aspects of a form's design that could change between
languages, etc. I don't understand how you can be critical of something
for being incomplete in a purpose for which it is not intended (for "not
including any non-localized customization").

I'm not meaning to argue for its own sake, I truly just am puzzled by your
statements.

Can I use a semi tractor/trailer to go get McDonald's? Yes, with some
special effort and some limitations. Should I criticize a semi
tractor/trailer for not fitting in the drive-in window? No, of course
not.


In raw Windows a form can be completely descibed in a self-contained ".rc"
file or its compiled ".res" equivalent. There's no such analogue in .NET
however so how do you pull a form out of a Visual Studio (VS) project so it
can be sent off to another program for processing? Let's say program A
exists on a machine without VS installed for instance and it justs wants to
display some form from an arbitrary VS project. The only practical way I can
seem to find to pull this off is to send all of the form's ".resx" or
".resources" file to program A (one such file for each supported language),
where program A can then construct a "System.Windows.Forms.Form" object and
apply all controls, properties, etc. found in these ".resx" files (with all
other properties already set to their default values at time of object
construction). Will this result in the same form that
"InitializeComponent()" creates back where the project is actually compiled?
(excluding whatever code the programmer adds after the call to
"InitializeComponent()"). No because "InitializeComponent()" sets certain
other properties in code that don't originate from the ".resx" file. So how
is program A supposed to know that it should also set these properties when
all it has is the ".resx" or "resources" files to work with. Maybe there's
another (non-trivial) way to do this such as a native .NET class that
program A can call to re-construct "InitializeComponent()" on-the-fly. It
eludes me so far however so maybe eating at McDonald's isn't always the
healthiest thing after all :)
Jun 22 '06 #7

P: n/a
Well, you could always dyamically load the resultant assembly and use
reflection to create an instance of the form? No VS required - just the
framework...

At the end of the day, not all forms involve resource files... does that
mean they aren't proper forms? I hope not...

(might want to think about security loading random dlls, but heh!)

Marc
Jun 22 '06 #8

P: n/a
> Well, you could always dyamically load the resultant assembly and use
reflection to create an instance of the form? No VS required - just the
framework...
How? I would have to send the assembly itself out (not good) and then what?
Any code that the programmer added after the call to "InitializeComponent()"
will also get executed. I have no idea what this could be so it's
potentially big trouble (could be doing anything from looking for a
non-existent DB in order to initialize the form to potentially violationg
the local security policy on the machine).
At the end of the day, not all forms involve resource files... does that
mean they aren't proper forms? I hope not...


In my case I'm dealing with localized forms only so by definition they
should be following the hub and spoke model (resources should exist).

Thanks for the feedback however :)
Jun 22 '06 #9

P: n/a

"Jake Forson" <no_spam@_nospam.com> wrote in message
news:eF**************@TK2MSFTNGP03.phx.gbl...

In raw Windows a form can be completely descibed in a self-contained ".rc"
file or its compiled ".res" equivalent. There's no such analogue in .NET
however so how do you pull a form out of a Visual Studio (VS) project so
it can be sent off to another program for processing? Let's say program A
exists on a machine without VS installed for instance and it justs wants
to display some form from an arbitrary VS project. The only practical way
I can seem to find to pull this off is to send all of the form's ".resx"
or ".resources" file to program A (one such file for each supported
language), where program A can then construct a
"System.Windows.Forms.Form" object and apply all controls, properties,
etc. found in these ".resx" files (with all other properties already set
to their default values at time of object construction). Will this result
in the same form that "InitializeComponent()" creates back where the
project is actually compiled? (excluding whatever code the programmer adds
after the call to "InitializeComponent()"). No because
"InitializeComponent()" sets certain other properties in code that don't
originate from the ".resx" file. So how is program A supposed to know that
it should also set these properties when all it has is the ".resx" or
"resources" files to work with. Maybe there's another (non-trivial) way to
do this such as a native .NET class that program A can call to
re-construct "InitializeComponent()" on-the-fly. It eludes me so far
however so maybe eating at McDonald's isn't always the healthiest thing
after all :)


Again, you speak of this as if it's some flaw in the design of .NET or VS or
something. I guess that's what is puzzling me.

My understanding is that you have a specific need to represent a form's
design in some neutral way for passing between programs. Sounds like custom
functionality to me. Are you trying to create your own forms
designer/editor?

Why would Program A need to "reconstruct" InitializeComponent? It either
has access to the .cs file and could read it itself or you need some kind of
custom transport. Maybe all my McDonalds is making me dense, but I'm not
just seeing why you're insisting on cramming the square peg into the round
hole.

You might want to check out the WPF / XAML capabilities in the upcoming
WinFX (now .NET framework 3.0 I guess). It provides the kind of decoupling
I think you're looking for.
Jun 23 '06 #10

P: n/a
> Again, you speak of this as if it's some flaw in the design of .NET or VS
or something. I guess that's what is puzzling me.

My understanding is that you have a specific need to represent a form's
design in some neutral way for passing between programs. Sounds like
custom functionality to me. Are you trying to create your own forms
designer/editor?

Why would Program A need to "reconstruct" InitializeComponent? It either
has access to the .cs file and could read it itself or you need some kind
of custom transport. Maybe all my McDonalds is making me dense, but I'm
not just seeing why you're insisting on cramming the square peg into the
round hole.

You might want to check out the WPF / XAML capabilities in the upcoming
WinFX (now .NET framework 3.0 I guess). It provides the kind of
decoupling I think you're looking for.


I didn't say it was a flaw in the design of .NET. It is inconvenient though.
In any case, I'm not sure why you're having trouble understanding my point
(no disrespect intended :) At its most rudimentary level, how would a
3rd-party program go about extracting a localized form from some solution
(given access to all its source code), and then send it off to another
program which can now read the form and all of its controls (even displaying
the form if it wants). How would you do it?
Jun 23 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.