TabPage...Better/Simpler way

M

meh

I'm not sure if I have the right concept going. I am making a custom TabPage and executing it from a button click event. It works fine I'm just thinking I might be missing the finer points of the c# language. If not maybe I'm starting to catch on. Would like comments...better???...simpler???...

Here is the code....

tia
meh

// Build New Tab Page
//
string title = "tabPage" + (tabControl1.TabCount + 1).ToString();
TabPage myTabPage = new TabPage(title);
tabControl1.TabPages.Add(myTabPage);
//
// Build New tabPage with treeView1
//
TreeView CurrTree = new TreeView();
CurrTree.Dock = System.Windows.Forms.DockStyle.Fill;
CurrTree.ImageIndex = -1;
CurrTree.Indent = 19;
CurrTree.ItemHeight = 16;
CurrTree.Location = new System.Drawing.Point(0, 44);
CurrTree.Name = "CurrTree" + (tabControl1.TabCount).ToString();
CurrTree.SelectedImageIndex = -1;
CurrTree.Size = new System.Drawing.Size(292, 428);
CurrTree.TabIndex = 3;
// Adds new node as a child node of the currently selected node.
TreeNode newNode = new TreeNode();
newNode.Text = "Text for new node";
newNode.ImageIndex = 0;
newNode.SelectedImageIndex = 1;
CurrTree.Nodes.Add(newNode);
CurrTree.SelectedNode = newNode;
//
// Build New tabPage with myComboBox
//
ComboBox myComboBox = new ComboBox();

myComboBox.Dock = System.Windows.Forms.DockStyle.Top;
myComboBox.ItemHeight = 13;
myComboBox.Location = new System.Drawing.Point(0, 23);
myComboBox.Name = "comboBox" + (tabControl1.TabCount).ToString();
myComboBox.Size = new System.Drawing.Size(292, 21);
myComboBox.TabIndex = 2;
myComboBox.Text = "comboBox" + (tabControl1.TabCount).ToString();
//
myTabPage.Controls.Add(CurrTree);
myTabPage.Controls.Add(myComboBox);
//
// keep the toolbar
myTabPage.Controls.Add(tabToolBar);
//
//
tabControl1.SelectedTab = myTabPage;
myTabPage.Text = CurrTree.Name;
statusBar1.Panels[0].Text = myTabPage.Text;
// tabToolBar.BringToFront();
break;
 
N

Nicholas Paldino [.NET/C# MVP]

meh,

What you are doing basically seems correct. I am curious though, are
you trying to do this dynamically? Is there a need to do it dynamically?
If not, I would let the designer handle all of this.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I'm not sure if I have the right concept going. I am making a custom
TabPage and executing it from a button click event. It works fine I'm just
thinking I might be missing the finer points of the c# language. If not
maybe I'm starting to catch on. Would like
comments...better???...simpler???...

Here is the code....

tia
meh

// Build New Tab Page
//
string title = "tabPage" + (tabControl1.TabCount + 1).ToString();
TabPage myTabPage = new TabPage(title);
tabControl1.TabPages.Add(myTabPage);
//
// Build New tabPage with treeView1
//
TreeView CurrTree = new TreeView();
CurrTree.Dock = System.Windows.Forms.DockStyle.Fill;
CurrTree.ImageIndex = -1;
CurrTree.Indent = 19;
CurrTree.ItemHeight = 16;
CurrTree.Location = new System.Drawing.Point(0, 44);
CurrTree.Name = "CurrTree" + (tabControl1.TabCount).ToString();
CurrTree.SelectedImageIndex = -1;
CurrTree.Size = new System.Drawing.Size(292, 428);
CurrTree.TabIndex = 3;
// Adds new node as a child node of the currently selected node.
TreeNode newNode = new TreeNode();
newNode.Text = "Text for new node";
newNode.ImageIndex = 0;
newNode.SelectedImageIndex = 1;
CurrTree.Nodes.Add(newNode);
CurrTree.SelectedNode = newNode;
//
// Build New tabPage with myComboBox
//
ComboBox myComboBox = new ComboBox();

myComboBox.Dock = System.Windows.Forms.DockStyle.Top;
myComboBox.ItemHeight = 13;
myComboBox.Location = new System.Drawing.Point(0, 23);
myComboBox.Name = "comboBox" + (tabControl1.TabCount).ToString();
myComboBox.Size = new System.Drawing.Size(292, 21);
myComboBox.TabIndex = 2;
myComboBox.Text = "comboBox" + (tabControl1.TabCount).ToString();
//
myTabPage.Controls.Add(CurrTree);
myTabPage.Controls.Add(myComboBox);
//
// keep the toolbar
myTabPage.Controls.Add(tabToolBar);
//
//
tabControl1.SelectedTab = myTabPage;
myTabPage.Text = CurrTree.Name;
statusBar1.Panels[0].Text = myTabPage.Text;
// tabToolBar.BringToFront();
break;
 
M

meh

Thanks Nick for the reply...
Yes I am trying to do this dynamically.
Yes there is a need
Impossible to know ahead of time what the user will do with this. This was
part of the spec ... that the user can "auto generate" multiple tabPages.
I am migrating over to C# from VB and am using this to try out a more c#
oriented philosophy.
I know there was a bug in VB when distroying tab pages....but I have not run
into that using C#.
Again thanks for the feedback...


meh
Nicholas Paldino said:
meh,

What you are doing basically seems correct. I am curious though, are
you trying to do this dynamically? Is there a need to do it dynamically?
If not, I would let the designer handle all of this.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I'm not sure if I have the right concept going. I am making a custom
TabPage and executing it from a button click event. It works fine I'm just
thinking I might be missing the finer points of the c# language. If not
maybe I'm starting to catch on. Would like
comments...better???...simpler???...

Here is the code....

tia
meh

// Build New Tab Page
//
string title = "tabPage" + (tabControl1.TabCount + 1).ToString();
TabPage myTabPage = new TabPage(title);
tabControl1.TabPages.Add(myTabPage);
//
// Build New tabPage with treeView1
//
TreeView CurrTree = new TreeView();
CurrTree.Dock = System.Windows.Forms.DockStyle.Fill;
CurrTree.ImageIndex = -1;
CurrTree.Indent = 19;
CurrTree.ItemHeight = 16;
CurrTree.Location = new System.Drawing.Point(0, 44);
CurrTree.Name = "CurrTree" + (tabControl1.TabCount).ToString();
CurrTree.SelectedImageIndex = -1;
CurrTree.Size = new System.Drawing.Size(292, 428);
CurrTree.TabIndex = 3;
// Adds new node as a child node of the currently selected node.
TreeNode newNode = new TreeNode();
newNode.Text = "Text for new node";
newNode.ImageIndex = 0;
newNode.SelectedImageIndex = 1;
CurrTree.Nodes.Add(newNode);
CurrTree.SelectedNode = newNode;
//
// Build New tabPage with myComboBox
//
ComboBox myComboBox = new ComboBox();

myComboBox.Dock = System.Windows.Forms.DockStyle.Top;
myComboBox.ItemHeight = 13;
myComboBox.Location = new System.Drawing.Point(0, 23);
myComboBox.Name = "comboBox" + (tabControl1.TabCount).ToString();
myComboBox.Size = new System.Drawing.Size(292, 21);
myComboBox.TabIndex = 2;
myComboBox.Text = "comboBox" + (tabControl1.TabCount).ToString();
//
myTabPage.Controls.Add(CurrTree);
myTabPage.Controls.Add(myComboBox);
//
// keep the toolbar
myTabPage.Controls.Add(tabToolBar);
//
//
tabControl1.SelectedTab = myTabPage;
myTabPage.Text = CurrTree.Name;
statusBar1.Panels[0].Text = myTabPage.Text;
// tabToolBar.BringToFront();
break;
 
Top