Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-13-2013, 07:23 PM   PM User | #1
leedbrierley
New to the CF scene

 
Join Date: Dec 2011
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
leedbrierley is an unknown quantity at this point
C# help with getting stuff to populate

Right I have this peace of code. I want it duplicate the textBox, and at the same time, I want them to appear on other tabs in a multidimensional array, I know there is a way of doing it, but I just dont have a bloody clue where to go it has had me perplexed most for over a week now. Any help would be appreciated

private void button1_Click(object sender, EventArgs e)
{
string title = "Round " + (tabControl1.TabCount + 1).ToString();
TabPage myTabPage = new TabPage(title);
tabControl1.TabPages.Add(myTabPage);
tabControl1.SelectedIndex = tabControl1.TabCount;

textBox9.Parent = tabControl1.TabPages[tabControl1.SelectedIndex];
label9.Parent = tabControl1.TabPages[tabControl1.SelectedIndex];
}
leedbrierley is offline   Reply With Quote
Old 01-14-2013, 05:41 AM   PM User | #2
negative zero
New to the CF scene

 
Join Date: Jan 2013
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
negative zero is an unknown quantity at this point
IIRC, you need to add the TextBox and Label controls to the Controls member of your TabPage... myTabPage.Controls.Add(...);

This: textBox9.Parent = tabControl1.TabPages[tabControl1.SelectedIndex];
... looks like it can be simplified to this: textBox9.Parent = myTabPage;
negative zero is offline   Reply With Quote
Old 01-20-2013, 02:41 PM   PM User | #3
AceInfinity
New Coder

 
Join Date: Jan 2013
Location: Canada
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
AceInfinity is an unknown quantity at this point
Code:
private void button1_Click(object sender, EventArgs e)
{
	string title = "Round " + (tabControl1.TabCount + 1).ToString();
	TabPage myTabPage = new TabPage(title);
	tabControl1.TabPages.Add(myTabPage);
	tabControl1.SelectedIndex = tabControl1.TabCount;

	textBox9.Parent = tabControl1.TabPages[tabControl1.SelectedIndex];
	label9.Parent = tabControl1.TabPages[tabControl1.SelectedIndex];
}
I can't understand why you are setting the SelectedIndex just to use it's value later on though here. Why not just use tabControl1.TabCount if that's the value you know you'll be using later on? SelectedIndex has other purposes.

If you're just setting the parent to a specific TextBox though then you're not duplicating anything. Same thing with that Label. Although pionting that out, this won't work anyways unless you use tabControl1.TabCount - 1, becuase the indexing is 0 based...

Example:
Code:
string title = "Round " + (tabControl1.TabCount + 1).ToString();
TabPage myTabPage = new TabPage(title);
tabControl1.TabPages.Add(myTabPage);

TextBox T = new TextBox()
{
	Text = textBox1.Text,
	Size = textBox1.Size
};

tabControl1.TabPages[tabControl1.TabCount - 1].Controls.Add(T);
*Set other properties for the new TextBox accordingly if you want to change the position or anything else... You can do it this way because each TabPage is a container for controls, so it has a Controls.Add() method.

Last edited by AceInfinity; 01-20-2013 at 02:44 PM..
AceInfinity is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


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

Forum Jump


All times are GMT +1. The time now is 10:09 AM.


Advertisement
Log in to turn off these ads.