473,419 Members | 1,618 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,419 software developers and data experts.

C# - Creating form objects from a base control?

Hi i just have a quick question.

I ran a search but i was not sure really how to word it correctly and couldnt find anything.

I would like to know how I can create a form object like a textbox, label or combo box from the one variable?

Obviously for a label it is easy by itself, i have just been doing..

public System.Windows.Forms.Label[,] obj_field_control = new System.Windows.Forms.Label[19, 9];

but now i want to have this public declaration as a variant type array that allows me to create different objects depending on what i assign it. Is this only possible through inheritence?

I want to make it

public System.Windows.Forms.VariantObjectThing[,] obj_field_control = new System.Windows.Forms.VariantObjectThing[19, 9];

and then simply be able to do

obj_field_control[0, 0] = new System.Windows.Forms.TextBox();
obj_field_control[0, 1] = new System.Windows.Forms.Label();
obj_field_control[0, 2] = new System.Windows.Forms.ComboBox();

I would appreciate any help :)

Thanks
Feb 12 '08 #1
5 2020
weaknessforcats
9,208 Expert Mod 8TB
I am moving this to the .NET forum.
Feb 12 '08 #2
Plater
7,872 Expert 4TB
Hmm.
You might be able to get away with using an array of Control[,] and then assigning the various index positions to be a TextBox or Label or whatever.
There is also a ControlCollection object that you can .Add() to?
Although you might consider trying to use a more generic approach and using like LinkedList (LinkedList<Control>) or ArrayList.
Feb 12 '08 #3
Hi thanks for the replys guys. Also sorry, i thought i did post it in the .net forum.

You suggested using the .control fuction correct? i have actually tried this before, but maybe my method was incorrect...

i have tried:

public System.Windows.Forms.Control[,] obj_field_control = new System.Windows.Forms.ComboBox[19, 9];

Just to see if any of of the combobox controls would actually work. However i get an error saying that the .item is not a recognised command for a control.

I have also tried:

public System.Windows.Forms.Control[,] obj_field_control = new System.Windows.Forms.Control[19, 9];

obj_field_control[0, 1] = new System.Windows.Forms.TextBox();

But it gave my the same kind of problem, as it only gives a generic amount of commands for the control.



That control collection add sounds like a good idea, but after i have added the object, how do i actually reference it?

obj_field_control[0, 1].Add(new System.Windows.Forms.TextBox());

What would i make this so i can reference the location of the textbox?

obj_field_control[0, 1].Location

EDIT

I have found that if i write the syntax like this:

obj_field_control[0, 1][0].Location

It works, however i find that the [0] is a bit of a pain as it will remove some of the efficiency of my program. Any ideas?

EDIT 2:

After trying it out a little bit i have still found that the control collection will not allow me to use properties that are uncommon with all objects. The .Item will still not work. Any suggestions?
Feb 13 '08 #4
Thanks for the help.

I managed to fix it myself. I just ended up using a Control and then type casting the controls like (TextBox). Works like a charm. Thanks
Feb 13 '08 #5
Plater
7,872 Expert 4TB
Yeah after your other post I was going to say you need to remember to cast the control back to it's correct type to get all the extra properties and such.
Feb 14 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum...
3
by: Darleen | last post by:
I am seeking conceptual here on how to get started with a "3D Matrix" in Access. We run a training center which holds multiple classes in multiple cities at multiple times. So I need to create a...
4
by: Jason M | last post by:
Hi, Im very new to c#, so forgive me if this is a really stupid question. Im trying to create a form for entering purchase requests. For each line item I have a quantity, a description unit cost...
3
by: Ken Varn | last post by:
I am just starting the process of creating ASP.NET server controls. I have created controls for .NET applications, but have just started with ASP.NET. I am a little confused about some areas that...
5
by: | last post by:
Trying to learn about manipulating collections of objects, and populating these objects dynamically from datasources. Could someone post a code sample that shows the following: Instantiating a...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
3
by: Tabi | last post by:
Hi, I have just created a class that removes action attribute from HtmlForm. The code looks like here. namespace ComIT.Applications.Common { public class Form :...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
26
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is...
5
by: Doc John | last post by:
I need to create several Windows Forms and I'm thinking of creating a base Form from which I can derive all Forms. Is it possible to include something in that Base Form so that all Forms I create...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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.