Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 15th, 2008, 8:05 AM   #1
beni_dude
Newbie
 
beni_dude's Avatar
 
Join Date: Apr 2008
Posts: 19
Rep Power: 0 beni_dude is on a distinguished road
Question cration of a new control, problem with adding new controls

Hello,
I have a problem when I try to add a new control to the panel control, I'm sure its a newbie problem but still I can't go around it!

What I'm trying to do is to create a new control which well be only one panel control and in it twelve text box (array of text box).

I'm also adding the code

Quote:
public partial class MonthPick : Control
{
public const int arrSize = 12;

public MonthPick()
{
InitializeComponent();

TextBox[] boxArr = new TextBox[arrSize];
initBoxArr(boxArr, arrSize);

//the problem is with the next line
panel1.Controls.Add = boxArr;
}

private void initBoxArr(TextBox[] boxArr, int arrSize)
{
for (int i = 0; i < arrSize; i++)
{
boxArr[i] = new TextBox();
}
}

protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}


}
I just don't know how to add the array of text box's

Thanks
beni_dude is offline   Reply With Quote
Old Apr 15th, 2008, 8:40 AM   #2
beni_dude
Newbie
 
beni_dude's Avatar
 
Join Date: Apr 2008
Posts: 19
Rep Power: 0 beni_dude is on a distinguished road
Re: cration of a new control, problem with adding new controls

The error that I receive is this:

Quote:
Cannot assign to 'Contains' because it is a 'method group'
beni_dude is offline   Reply With Quote
Old Apr 15th, 2008, 10:19 AM   #3
beni_dude
Newbie
 
beni_dude's Avatar
 
Join Date: Apr 2008
Posts: 19
Rep Power: 0 beni_dude is on a distinguished road
Re: cration of a new control, problem with adding new controls

I just might figured it by myself I just used this code:

Quote:
panel1.Controls.Add(textBox1);
But now I have something new, I need to see the text box (in the new command that I have created) and that I don't know how to do.
__________________
NULL is all around me!
beni_dude is offline   Reply With Quote
Old Apr 15th, 2008, 11:22 AM   #4
beni_dude
Newbie
 
beni_dude's Avatar
 
Join Date: Apr 2008
Posts: 19
Rep Power: 0 beni_dude is on a distinguished road
Re: cration of a new control, problem with adding new controls

I just want to create a control with 12 other controls I can't believe its so hard
__________________
NULL is all around me!
beni_dude is offline   Reply With Quote
Old Apr 15th, 2008, 4:07 PM   #5
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,010
Rep Power: 5 lectricpharaoh will become famous soon enough
Re: cration of a new control, problem with adding new controls

Are you trying to actually create a new control (ie, a custom control), or are you just trying to stick a bunch of stuff onto a panel? If it's the former, it's a little involved, particularly if you want design-time support (support in the drag-and-drop 'forms designer'). If it's the latter, you can just add them in the designer. If you need to iterate through them with array notation, you add the TextBoxes (or whatever) in the designer, and give them descriptive names (not necessary, but a good habit to get into). Then, in your code, you create an array of TextBoxes, and assign the references:
C# Syntax (Toggle Plain Text)
  1. TextBox[] textBoxArray = new TextBox[numberOfTextBoxes];
  2. textBoxArray[0] = txtInput;
  3. textBoxArray[1] = txtOutput;
  4. textBoxArray[2] = txtSomethingElse;
  5. // and so on
Now you can process them in a loop, which is probably why you want to use an array:
C# Syntax (Toggle Plain Text)
  1. for(int x=0; x<textBoxArray.Length; ++x)
  2. textBoxArray[x].Text = x.ToString();
Remember that even though you can create an array of controls, you still need to initialize each element of the array appropriately. The designer is the easiest way to do this; otherwise, you need to set the width, height, location, etc of each one individually.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Apr 15th, 2008, 4:31 PM   #6
beni_dude
Newbie
 
beni_dude's Avatar
 
Join Date: Apr 2008
Posts: 19
Rep Power: 0 beni_dude is on a distinguished road
Re: cration of a new control, problem with adding new controls

First thing thanks for the Replay!

Second yes I'm trying to create an custom control which is a bit of a problem.
Now I did manage to create the array of the controls (in this case array of text box) but WHEN I create it in the panel and make sure to add the text box array I get only one text box, I think that its actually the twelfth box's in the same position so now I need to move them in the panel so they won't be on the top of each other.

If some one can come up with a simple clear cut way it will be great!
__________________
NULL is all around me!
beni_dude is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
adding an image control at run time diamondustice Visual Basic 4 Feb 19th, 2006 9:12 PM
How to handle keyboard events in an app containing ActiveX Controls ? George Giolfan Visual Basic .NET 0 Aug 7th, 2005 3:07 AM
Debugging ActiveX controls (.ocx) in Delphi 5 nauman73 Delphi 1 Jun 27th, 2005 4:13 PM
Tab controls some1 C++ 0 Apr 17th, 2005 3:28 PM
adding control variables Jayydedd Java 2 Mar 23rd, 2005 3:22 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:18 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC