473,405 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

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
Sep 6 '06 #1
5 1975
Perhaps an inherited form/control?
"Guillaume BRAUX" <v-******@nospam-microsoft.comwrote in message
news:44***********************@news.orange.fr...
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

Sep 6 '06 #2
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
Sep 6 '06 #3

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.

Sep 6 '06 #4
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" <br*******@canada.coma écrit dans le message
news:<11*********************@h48g2000cwc.googlegr oups.com>...
>
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.
Sep 7 '06 #5
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" <br*******@canada.coma écrit dans le message
news:<11*********************@h48g2000cwc.googlegr oups.com>...

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.
Sep 7 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vannela | last post by:
In my unmanaged there is code i n this way Class1 c1= new Class1(); // Class1 is one object and creating a instance of it\ Class1 c2= new Class2();// Class2 is another object a...
2
by: jm | last post by:
I have a Form1 and two class files. In the first class, I call the second class. The second class references the Form1 notifyicon and changes the icon. It works. The problems is, however,...
9
by: Christopher Weaver | last post by:
Can anyone tell me how I could iterate through a collection of controls on a form while assigning their event handlers to another identical collection of controls on the same form. So far,...
0
by: Søren M. Olesen | last post by:
How do I manipulate a control in one frame from another frame ?? I've tried something like: Class1 TextBox.Text="Text1" Session("TextBox")=TextBox1 Class2
5
by: John | last post by:
Hi I would like to create a compiled library .net code which I can use in my apps using imports and with references like mynamespace.myclass.mothod1. What is the way to create such libraries? ...
16
by: tshad | last post by:
This is a little complicated to explain but I have some web services on a machine that work great. The problem is that I have run into a situation where I need to set up my program to access one...
8
by: redeagle | last post by:
I'm wondering what the best practice is for creating a WinApp "wizard" that contains 4 or 5 "steps". Options so far are 1) Single WinForm making various controls visible/non visible at the...
2
by: saeed rezaei | last post by:
how i can write some property form mycontrol that's can be expend. when i use this cod : property MyProp as integer .... .... .... end property its only add one property to my control but...
5
by: CSharper | last post by:
I have a hashtable which has key and value. If the key is set to 'a' then I need to create a class1 and if it has key 'b' then I need to create class2 etc. (There is no name relation between the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.