473,842 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.EventArg s)Handles btnNewTab.Click

MyFrom1.TabPage 1 = New TabPage

' Adds the tabPage1 to this collection.
MyFrom1.TabCont rol1.TabPages.A dd(MyFrom1.TabP age1)

' Name the Tab
MyFrom1.TabPage 1.Text = "myTabPage"
MyFrom1.TabCont rol1.Refresh()

End Sub
Thanks

Tom
Nov 21 '05 #1
3 2243
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.Tab Pages.Add(New TabPage("myTabP age"))
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.EventArg s)Handles btnNewTab.Click

MyFrom1.TabPage 1 = New TabPage

' Adds the tabPage1 to this collection.
MyFrom1.TabCont rol1.TabPages.A dd(MyFrom1.TabP age1)

' Name the Tab
MyFrom1.TabPage 1.Text = "myTabPage"
MyFrom1.TabCont rol1.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.tabc ontrol1.Pages.A dd(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
1815
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
1118
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 after the InitializeComponent(); command, I write: if (this.tabControl1.SelectedTab == tabCoS) { CurrencyManager cm = (CurrencyManager)dg.BindingContext; cm.ItemChanged += new ItemChangedEventHandler(cm_ItemChanged);
3
2349
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 page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example ABAP, BDC etc..etc.. on every click event as Checkboxes. And these controls(checkboxes) should remain...
6
3137
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 ToolbarButtons... Does anyone know how this could be done? Looking forward to hear from you,
2
8121
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 = "Hello"; f.Text = "NEW"; f.Size = new Size(100, 100); f.Controls.Add(b); f.TopLevel = false;
1
1139
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 and many others. Any and all assistance to place the UI's on the tabs would be greatly appreciated. Michael
34
20263
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 being opened via the standard DoCmd call. I've tried adding Requery in AfterUpdate, Form_Current, etc. to no avail.... The test form has the combobox and a command button. Here's my test code: Private Sub cmdAddCatgCd_Click() On Error GoTo...
2
9975
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
2016
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)); thread.IsBackground = true; thread.Start(); In Form2 I have: public delegate void mydata(String e);
0
9871
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10944
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10610
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10313
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9453
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7855
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7035
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4089
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.