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

Adding a tab to a TabControl1 from another Form

My Program has two forms From1 and Form2.
On From1 I have a TabControl1 witch has
8 tabs currently. I would like to add a new
tab from Form2 is this possible?
I have tried the following code on Form2
with no success:

Public MyFrom1 As New From1

Private Sub btnNewTab_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)Handles btnNewTab.Click

MyFrom1.TabPage1 = New TabPage

' Adds the tabPage1 to this collection.
MyFrom1.TabControl1.TabPages.Add(MyFrom1.TabPage1)

' Name the Tab
MyFrom1.TabPage1.Text = "myTabPage"
MyFrom1.TabControl1.Refresh()

End Sub
Thanks

Tom
Nov 21 '05 #1
3 2219
Is this code on Form2 and you already have Form1 open? If I'm right, You just
created another Form1 in the memory in addition to the Form1 that already
open. If you open Form1 before Form2, pass Form1 to Form2 in the constructor
as a parameter, save it in the class level, and do all the adding tab work on
this variable.
You can do it in one line:
tabControl1.TabPages.Add(New TabPage("myTabPage"))
Where tabControl1 is the class level variable that points to Form1 instance.

"Tom McL." wrote:
My Program has two forms From1 and Form2.
On From1 I have a TabControl1 witch has
8 tabs currently. I would like to add a new
tab from Form2 is this possible?
I have tried the following code on Form2
with no success:

Public MyFrom1 As New From1

Private Sub btnNewTab_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)Handles btnNewTab.Click

MyFrom1.TabPage1 = New TabPage

' Adds the tabPage1 to this collection.
MyFrom1.TabControl1.TabPages.Add(MyFrom1.TabPage1)

' Name the Tab
MyFrom1.TabPage1.Text = "myTabPage"
MyFrom1.TabControl1.Refresh()

End Sub
Thanks

Tom

Nov 21 '05 #2
Amiram,

I called From2 from Form1 as a ShowDialog()

Now I am at a loss, I don't understand Constructors is the constructor
created
in Form2?

A short example would help a lot if you have time. I have been working with
VB 5 and tring to understand VB.net.

Thanks again

Tom
Nov 21 '05 #3
You can find a sub named "New" in the hidden section of your form. This is a
constructor.

Add a variable to hold Form1 reference:
private ParentForm AS Form1

Add your own constructor (leave the hidden one)
Public Sub New(ByVal ParentForm as Form1)
Me.ParentForm = ParentForm
End Sub

Whenever you need to add pages to the tabcontrol write:
ParentForm.tabcontrol1.Pages.Add(New TabPage("name"))

I suggest you change the names Form1 and Form2 to meaningful names. If you
came from vb5, take some time to learn vb.net, especially classes and
inheritance before you start.
"Tom McL." wrote:
Amiram,

I called From2 from Form1 as a ShowDialog()

Now I am at a loss, I don't understand Constructors is the constructor
created
in Form2?

A short example would help a lot if you have time. I have been working with
VB 5 and tring to understand VB.net.

Thanks again

Tom

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Liz | last post by:
I am trying to add a label to a tab page tabMain.TabPages.Controls.Add(aLabel); and get an error "specified argument was out of the range of valid values. Any ideas???
0
by: melanieab | last post by:
Hi, I want to add an ItemChangedEventHandler so that when the user clicks on a column header in a datagrid (and sorting takes place), the cm_ItemChanged event fires. At the very beginning, just...
3
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users...
6
by: Juan Pedro Gonzalez | last post by:
I wanted to add a Combobox to a toolbar... Kind of the look you get on VisualStudio's toolbar. I've been able to find some VB 6 samples, but the placeholder option is no longer available for...
2
by: TN | last post by:
I can add a button to a TabPage, how come I can't add a Form? The Form never gets realized on the page, but a button can :-( f = new System.Windows.Forms.Form(); b = new Button(); b.Text =...
1
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. I have an application that has a tab control and I have UI user controls I wish to populate various tabs with and I've tried the forms.UIname.show...
34
by: bitsnbytes64 | last post by:
Hi, I've been having a similar issue to what is described in the "refresh a form" post with a ComboBox that is not being refreshed after adding a new value on a seperate form. The second form is...
2
by: Rob | last post by:
Hi, I am adding Tab pages to a Tab control dynamically via the following statement... Form1.TabControl1.Controls.Add(ThePage) The next 2 statements also work... ThePage.Name = some string
1
by: RobcPettit | last post by:
Hi, I have two forms. From form1(frmMain) I want to add tabpages to Form2. In form1 I have: frmMain tbe = new frmMain(); Thread thread = new Thread(new ThreadStart(tbe.AddTab));...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.