|
-
Jan 13th, 2006, 03:02 AM
#1
Thread Starter
Member
[RESOLVED] Control Containers
Hi i'm new to VB .NET but have been using VB6 for about a year. I am currently struggling with control arrays as they are not a feature of VB anymore
So far I have been able to 'duplicate' controls by creating a control array class, but I can't figure out how to add the new controls to a TabPage in my form - I can only add it to the form:
VB Code:
Form1.Controls.Add(Button1)
Please show me to choose the parent controls of the controls created in my control array class.
-
Jan 13th, 2006, 03:27 AM
#2
Re: Control Containers
Every control has a Controls property. If you want to add a control to a TabPage then you simply add it to the TabPage's Controls collection instead of the form's.
Also, a ControlArray class is pretty pointless because you can still create an array of Controls. The difference from VB6 to VB.NET is that you can't create them in the designer and the controls themselves have no Index property. To change the first of these situations you'd have to add functionality to your class that allowed it to be created in the designer, which I'll wager that you haven't. To change the second situation you'd have to inherit EVERY control and add an Index property, which is totally impractical. Basically, ControlArrays aren't needed in VB.NET. There is all sorts of stuff written on this subject on this forum, on MSDN and elsewhere.
-
Jan 13th, 2006, 04:03 AM
#3
Thread Starter
Member
Re: Control Containers
Thanks for that, but when i try to add a control to a container in the form it gives me the message:
"Object reference not set to an instance of an object."
...
-
Jan 13th, 2006, 04:16 AM
#4
Re: Control Containers
Does your TabControl actually contain any TabPages?
-
Jan 13th, 2006, 04:27 AM
#5
Thread Starter
Member
-
Jan 13th, 2006, 05:01 AM
#6
Re: Control Containers
Then you need to debug your code. There is no reason to be posting a question about a NullReferenceException. You just press the Break button on the Unhandled Exception dialogue and examine each reference on that line. You can use the Watch window to evaluate any expression you like until you find a reference (variable, property or function result) that is Nothing. Then you work backwards to find the place you expected that object to be created.
-
Jan 13th, 2006, 06:10 AM
#7
PowerPoster
Re: Control Containers
Hi,
Whilst it is possible to create controls and add them to an array in the Designer, that is making very heavy work of it. It is far easier to do it in code. Look at
http://www.vbforums.com/showthread.php?t=328100
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jan 13th, 2006, 09:33 AM
#8
Thread Starter
Member
Re: Control Containers
Thanks for the help guys. Taxes that's a great explanation of control arrays.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|