PC Review


Reply
Thread Tools Rate Thread

Creating a control in Class1 ... and showing it in Class2 (winform)

 
 
Guillaume BRAUX
Guest
Posts: n/a
 
      6th Sep 2006
Hello,

What I want to do is to add a userControl to a form class witch is a
different class from the one the button is generated.
For example, I want to instanciate a label in "class1" and add it ("show
it") on a WinForm situated in "class2" (without having to add code to class2
!)

The problem is that I need to instanciate "class2" from "class1" to be able
to do a class2.controls.add(myLabel) in class1..
Instaciating class2 means that a new form will be created, but i want my
control to be added to the current running form.

Thanks for your help,

Guill


 
Reply With Quote
 
 
 
 
jereviscious
Guest
Posts: n/a
 
      6th Sep 2006
Perhaps an inherited form/control?
"Guillaume BRAUX" <v-(E-Mail Removed)> wrote in message
news:44ff34e9$0$27412$(E-Mail Removed)...
> Hello,
>
> What I want to do is to add a userControl to a form class witch is a
> different class from the one the button is generated.
> For example, I want to instanciate a label in "class1" and add it ("show
> it") on a WinForm situated in "class2" (without having to add code to
> class2 !)
>
> The problem is that I need to instanciate "class2" from "class1" to be
> able to do a class2.controls.add(myLabel) in class1..
> Instaciating class2 means that a new form will be created, but i want my
> control to be added to the current running form.
>
> Thanks for your help,
>
> Guill
>



 
Reply With Quote
 
Guillaume BRAUX
Guest
Posts: n/a
 
      6th Sep 2006
> Perhaps an inherited form/control?

Already tried ... My control class inherit from my form class, but il does
not help ... I still have to instaciate the form to be able to do a control
add (class2.controls.add(myLabel)) ...

Thanks


 
Reply With Quote
 
Bruce Wood
Guest
Posts: n/a
 
      6th Sep 2006

Guillaume BRAUX wrote:
> > Perhaps an inherited form/control?

>
> Already tried ... My control class inherit from my form class, but il does
> not help ... I still have to instaciate the form to be able to do a control
> add (class2.controls.add(myLabel)) ...
>
> Thanks


What are you trying to do? I see questions like this posted to
newsgroups from time to time, in which the OP asks how to achieve some
effect, then after a half-dozen posts it turns out that the problem is
to set the label text at run-time, or make a label disappear at
run-time, or something like that, all of which is very easy to do using
other means.

So... could you step back a bit and tell us what you're trying to
achieve? Why do you want to add a label at runtime? What is that going
to do for you?

Perhaps there's another, much easier way to do what you want to do.

 
Reply With Quote
 
Guillaume BRAUX
Guest
Posts: n/a
 
      7th Sep 2006
Here is exactly what I want to do in my app :

The main problem is that my app will work with a totaly dynamic GUI, so
buttons, label and so on have to be created at runtime.

> When I click on a runtime created button, I want to load a UserControl

not yet instaciated and put it on a TabPage also created at runtime

How can I achieve this goal ?

Thanks,

Guillaume


"Bruce Wood" <(E-Mail Removed)> a écrit dans le message
news:<(E-Mail Removed)>...
>
> Guillaume BRAUX wrote:
> > > Perhaps an inherited form/control?

> >
> > Already tried ... My control class inherit from my form class, but il
> > does
> > not help ... I still have to instaciate the form to be able to do a
> > control
> > add (class2.controls.add(myLabel)) ...
> >
> > Thanks

>
> What are you trying to do? I see questions like this posted to
> newsgroups from time to time, in which the OP asks how to achieve some
> effect, then after a half-dozen posts it turns out that the problem is
> to set the label text at run-time, or make a label disappear at
> run-time, or something like that, all of which is very easy to do using
> other means.
>
> So... could you step back a bit and tell us what you're trying to
> achieve? Why do you want to add a label at runtime? What is that going
> to do for you?
>
> Perhaps there's another, much easier way to do what you want to do.
>


 
Reply With Quote
 
Bruce Wood
Guest
Posts: n/a
 
      7th Sep 2006
So, you have a dynamic GUI that must be built at runtime. It sounds
like you have one form being built, and another form in which the user
is making choices that builds things into the first form. Am I right?

I'm going to make an assumption. I'm going to assume that the form
you're building is dynamic, but not completely arbitrary. By that I
mean that the user isn't saying things like, "Place a radio button
here." Rather, the user is making some choice like "I want a topping on
my sundae" and that causes certain controls to be placed on the second
form. Probably nothing so trivial, but you get the idea.

The other possibility is that you're writing a completely
general-purpose GUI builder, in which case the following advice doesn't
apply.

I would write methods and properties on the first form (the one being
dynamically built) that are based _not_ on what controls get added, but
on _why_ they're being added. So, to continue my silly example, you
might have a method on Form1 like this:

public void AllowToppingSelection(ArrayList toppings)
{ ... }

This method the contains the code to place the correct radio buttons on
the form to select amongst the indicated sundae toppings.

The idea here is that the client form (the one asking to add controls
to the form being built) doesn't have to know how the dynamic form is
offering that selection to the user. The client is concerned with
client-side things: ice cream flavours, toppings, cone type, cone
size... stuff like that. It builds the dynamic form by telling it
_what_ the user wants, not _how_ to add the controls. This allows the
client to work in a higher level of abstraction, and leaves the
complexities of how to place controls entirely within the dynamic
form's code.

As I said, the alternative is that you're building a completely generic
GUI builder, where there is no higher level of abstraction. That's
beyond my expertise... perhaps someone else here can comment on how to
do that, if that's your case.

Guillaume BRAUX wrote:
> Here is exactly what I want to do in my app :
>
> The main problem is that my app will work with a totaly dynamic GUI, so
> buttons, label and so on have to be created at runtime.
>
> > When I click on a runtime created button, I want to load a UserControl

> not yet instaciated and put it on a TabPage also created at runtime
>
> How can I achieve this goal ?
>
> Thanks,
>
> Guillaume
>
>
> "Bruce Wood" <(E-Mail Removed)> a écrit dans le message
> news:<(E-Mail Removed)>...
> >
> > Guillaume BRAUX wrote:
> > > > Perhaps an inherited form/control?
> > >
> > > Already tried ... My control class inherit from my form class, but il
> > > does
> > > not help ... I still have to instaciate the form to be able to do a
> > > control
> > > add (class2.controls.add(myLabel)) ...
> > >
> > > Thanks

> >
> > What are you trying to do? I see questions like this posted to
> > newsgroups from time to time, in which the OP asks how to achieve some
> > effect, then after a half-dozen posts it turns out that the problem is
> > to set the label text at run-time, or make a label disappear at
> > run-time, or something like that, all of which is very easy to do using
> > other means.
> >
> > So... could you step back a bit and tell us what you're trying to
> > achieve? Why do you want to add a label at runtime? What is that going
> > to do for you?
> >
> > Perhaps there's another, much easier way to do what you want to do.
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Showing a winform in Excel is slow the first time Torben Laursen Microsoft C# .NET 3 11th Apr 2007 08:42 PM
create form object in class2.vb Supra Microsoft VB .NET 6 24th Dec 2004 03:30 PM
WinForm DataGrid Column - Showing Lookup Value instead of Int Ed West Microsoft C# .NET 0 4th Nov 2004 05:39 AM
Re: NEWBIE-->Making a WinForm control and ActiveX control Ed Kaim [MSFT] Microsoft Dot NET Framework Forms 0 4th Apr 2004 05:28 AM
Creating many class instances without doing class1, class2, class3, etc. Adam Microsoft VB .NET 5 12th Feb 2004 01:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:00 AM.