471,337 Members | 941 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Dynamic forms

guy
Has anyone any experience of building a form at run time?
I have an app that will require 50+ simple forms, it will only be used by
me, so appearance isnt important.

My idea is to pass a business object to a standard form and use reflexion to
determine what controls are needed, maybe using custom attributes to help
this.

any thoughts?

cheers

guy
Jul 21 '05 #1
13 1197
Guy,

You are always building a form at run time in dotNet..
Most often you use an inherited form that is inherited from
system.control.forms.form, however it is build at run time.

The form you build can always be used because it is a class by the wat

In VBNet
dim frm1 as new myform
dim frm2 as new myform
etc.

In C#
myform frm1 = new myform();
etc.

I hope this helps?

Cor
Jul 21 '05 #2
guy
Hi Cor yes i realise this:-)

what i intend is to pass a form an object, and have the form use reflexiton
to determine what controls are needed , thjat way i can have one form and use
it for working with multiple business objects

cheers

guy

"Cor Ligthert" wrote:
Guy,

You are always building a form at run time in dotNet..
Most often you use an inherited form that is inherited from
system.control.forms.form, however it is build at run time.

The form you build can always be used because it is a class by the wat

In VBNet
dim frm1 as new myform
dim frm2 as new myform
etc.

In C#
myform frm1 = new myform();
etc.

I hope this helps?

Cor

Jul 21 '05 #3
Guy,

I do not understand you, when you know what controls are needed you can just
add them to the form.

What reflection you need for that from the form class?

Cor
Jul 21 '05 #4
There is a region in all .net forms created with VS.net that is labeled:

"Windows Form Designer generated code"

I would suggest you create a new form expand this section and look at how
the controls are created. Then mimic this in creating your check boxes,
Group Boxes, TextBoxes, etc...

Each control created gets added to a controls collection, if you always want
to start with a blank form for the new business object you can just call
controls.clear(); Otherwise I would suggest that you create your own
collection that will hold Objects and when you need to clear the form you
spin through your collection and call controls.remove(current object);

Hope this helps.
--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

"guy" <gu*@discussions.microsoft.com> wrote in message
news:81**********************************@microsof t.com...
Hi Cor yes i realise this:-)

what i intend is to pass a form an object, and have the form use reflexiton to determine what controls are needed , thjat way i can have one form and use it for working with multiple business objects

cheers

guy

"Cor Ligthert" wrote:
Guy,

You are always building a form at run time in dotNet..
Most often you use an inherited form that is inherited from
system.control.forms.form, however it is build at run time.

The form you build can always be used because it is a class by the wat

In VBNet
dim frm1 as new myform
dim frm2 as new myform
etc.

In C#
myform frm1 = new myform();
etc.

I hope this helps?

Cor

Jul 21 '05 #5
guy
Cor,Wayne,
I am obviously not making myself clear:-)
what I intend (and the prototype works)
is to instantiate one form, pass it a business object, and have the form
decide what controls are needed.
so, if I pass it a BO with properties ID and Name it gives me the
appropriate labels and text boxes,
however if I pass It a BO with properties ID, Invoice Value, CstomerName and
Product Code it again displays the appropriate lables and text boxes.
I ave got this far and it works
I am now looking at using custom attributes to enhance the form.
The overall idea is to only have to code up openform, and have all the
simple BOs in the app use it.
(this is a part time app, and i have only about 3 hours a week to work on
it! - and its got 50+BOs so I dont want to code up 50+ forms!)

yes , im a lazy bu***r but coding individual Winforms is sooo boring - been
doing it since VS.net beta one

guy

"Cor Ligthert" wrote:
Guy,

I do not understand you, when you know what controls are needed you can just
add them to the form.

What reflection you need for that from the form class?

Cor

Jul 21 '05 #6
Guy,

We try to tell you to take a simple approach first, to do it difficult can
every fool the chalange is to do it easy and therefore very well
maintanable.
however if I pass It a BO with properties ID, Invoice Value, CstomerName
and
Product Code it again displays the appropriate lables and text boxes.


It is not possible that you can do it like this

We take your problem above, this means that you have lets assume that you
use labels and textboxes for that

5 labels with in the label.text the names ID, Invoice, Value, CstomerName,
Product Code
5 textboxes which have the tage ID, Invoice, etc

Those you can build dynamicly (in VBNet dim txt(0) textbox : txt(0) = new
textbox) and add them too the form and set the handlers using addhandler.

You can probably use than a for each routine to bind your properties from
the business object to the textboxes depending on their TagName.

What do I miss in this?

Cor

Jul 21 '05 #7
guy


"Cor Ligthert" wrote:
Guy,

We try to tell you to take a simple approach first, to do it difficult can
every fool the chalange is to do it easy and therefore very well
maintanable.
however if I pass It a BO with properties ID, Invoice Value, CstomerName
and
Product Code it again displays the appropriate lables and text boxes.
It is not possible that you can do it like this

*** It is possible, I have done it, it works :-) - i will post the code
tomorrow ***
We take your problem above, this means that you have lets assume that you
use labels and textboxes for that

5 labels with in the label.text the names ID, Invoice, Value, CstomerName,
Product Code
5 textboxes which have the tage ID, Invoice, etc

Those you can build dynamicly (in VBNet dim txt(0) textbox : txt(0) = new
textbox) and add them too the form and set the handlers using addhandler.

You can probably use than a for each routine to bind your properties from
the business object to the textboxes depending on their TagName.

What do I miss in this?
I will post the code tomorrow when I have tidied it up :-)

guy
Cor

Jul 21 '05 #8
Think I understand a bit more now, you have it creating the forms and doing
the lay out already, but what you are wanting to do is use custom attributes
to decide what Control to create? and maybe where to place it?

Wayne

"guy" <gu*@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...


"Cor Ligthert" wrote:
Guy,

We try to tell you to take a simple approach first, to do it difficult can every fool the chalange is to do it easy and therefore very well
maintanable.
however if I pass It a BO with properties ID, Invoice Value, CstomerName and
Product Code it again displays the appropriate lables and text boxes.


It is not possible that you can do it like this

*** It is possible, I have done it, it works :-) - i will post the code
tomorrow ***

We take your problem above, this means that you have lets assume that you use labels and textboxes for that

5 labels with in the label.text the names ID, Invoice, Value, CstomerName, Product Code
5 textboxes which have the tage ID, Invoice, etc

Those you can build dynamicly (in VBNet dim txt(0) textbox : txt(0) = new textbox) and add them too the form and set the handlers using addhandler.
You can probably use than a for each routine to bind your properties from the business object to the textboxes depending on their TagName.

What do I miss in this?

I will post the code tomorrow when I have tidied it up :-)

guy
Cor

Jul 21 '05 #9
guy
hi Wayne,
exactly:-)
my question wasnt so much 'how do i do this?' rather 'has anyone else done
this?'
as I have a prototype working ok
I am just interested in wether anyone else has tried this approach
sorry i didnt make this clear

cheers

guy

"Wayne" wrote:
Think I understand a bit more now, you have it creating the forms and doing
the lay out already, but what you are wanting to do is use custom attributes
to decide what Control to create? and maybe where to place it?

Wayne

"guy" <gu*@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...


"Cor Ligthert" wrote:
Guy,

We try to tell you to take a simple approach first, to do it difficult can every fool the chalange is to do it easy and therefore very well
maintanable.

> however if I pass It a BO with properties ID, Invoice Value, CstomerName > and
> Product Code it again displays the appropriate lables and text boxes.

It is not possible that you can do it like this

*** It is possible, I have done it, it works :-) - i will post the code
tomorrow ***

We take your problem above, this means that you have lets assume that you use labels and textboxes for that

5 labels with in the label.text the names ID, Invoice, Value, CstomerName, Product Code
5 textboxes which have the tage ID, Invoice, etc

Those you can build dynamicly (in VBNet dim txt(0) textbox : txt(0) = new textbox) and add them too the form and set the handlers using addhandler.
You can probably use than a for each routine to bind your properties from the business object to the textboxes depending on their TagName.

What do I miss in this?

I will post the code tomorrow when I have tidied it up :-)

guy
Cor


Jul 21 '05 #10
Guy,
I am just interested in wether anyone else has tried this approach
sorry i didnt make this clear


I have seen a lot in the language.vb group who started your approach.

It looks a little bit as trying to reinvent or create an own MS-access.

However although you have the advantage that you have not to be compatible
with all older MS-access versions, will it be a hard way to go, for that
your clients are statisfied. Don't become sad when they everytime ask you
why they cannot do what is done with Ms-Access so easy with your program.

Just my thought,

Cor
Jul 21 '05 #11
guy
Hi Cor, Its actually using a SQL Server backend. I will ***defintiely*** be
the only user of the system so the fact that it is not pretty is ok.

cheers

guy

"Cor Ligthert" wrote:
Guy,
I am just interested in wether anyone else has tried this approach
sorry i didnt make this clear


I have seen a lot in the language.vb group who started your approach.

It looks a little bit as trying to reinvent or create an own MS-access.

However although you have the advantage that you have not to be compatible
with all older MS-access versions, will it be a hard way to go, for that
your clients are statisfied. Don't become sad when they everytime ask you
why they cannot do what is done with Ms-Access so easy with your program.

Just my thought,

Cor

Jul 21 '05 #12
Guy,

I mean a MS Access application, not the database, AFAIK can MS Access as
well use a SQL server as backend.

However when it is for yourself, than it can be a greath project for at
least learing a lot.

:-)

Cor
Jul 21 '05 #13
guy
Exactly:-)

"Cor Ligthert" wrote:
Guy,

I mean a MS Access application, not the database, AFAIK can MS Access as
well use a SQL server as backend.

However when it is for yourself, than it can be a greath project for at
least learing a lot.

:-)

Cor

Jul 21 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Nathan Bloomfield | last post: by
1 post views Thread by mtech1 | last post: by
3 posts views Thread by MikeY | last post: by
7 posts views Thread by AdeelAlvi | last post: by
2 posts views Thread by deejayquai | last post: by
3 posts views Thread by RahimAsif | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.