d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Visual Studio
12Next
Add Reply New Topic New Poll
Member
Posts: 3,439
Joined: Jan 1 2007
Gold: 128,248.52
Jan 19 2016 02:19pm
So say I have a windows form with a tabcontrol there is one tab named say "tab 1" then another "+" I need it so whenever I click + on the tabcontrol x happens. None of the code ive found around the net works and im not sure why microsoft didnt just add it into the control to begin with but hey.
Code
If tabcontrol.index = ("+") then
msgbox("It Worked!")
end if

Something like this for example
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jan 19 2016 02:41pm
I assume this is on the click (or some other event)? One of your args probably tells you which tab. I'm on mobile, so I won't look up the documentation myself.
Member
Posts: 3,439
Joined: Jan 1 2007
Gold: 128,248.52
Jan 19 2016 05:34pm
Yeah im guessing
Code
Private Sub Tabcontrol1_Click(sender As Object, e As EventArgs) Handles TabControl1.Click
If True = myTabpage Then
MsgBox("It Worked!")
End If
End Sub

This is the closest ive found so far that looks like it could jive but cant make it work.
Code

tabcontrol.SelectedTab == newTabPage
tabControl.TabPages.Insert(tabControl.TabPages.Count - 1, createdTabPage);
tabControl.SelectedTab = createdTabPage;


Code

if(e.TabPageIndex==tabControl1.TabPages.Count-1)
tabControl1.TabPages.Insert(tabControl1.TabPages.Count - 1,"tab"+e.TabPageIndex);
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jan 19 2016 06:49pm
Member
Posts: 3,439
Joined: Jan 1 2007
Gold: 128,248.52
Jan 19 2016 08:20pm
Thanks for all the help but I have worked on this all day and I cant get any of the examples to work. From my experience that websites worse then useless unless you are a Microsoft tech or have already gone to school for this area though. :(
Code
Private Sub NewTabToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NewTabToolStripMenuItem.Click
Dim myTabPage As New TabPage()
myTabPage.Text = "TabPage" & (Tab2.TabPages.Count + 1)
Tab2.TabPages.Add(myTabPage)
Dim MyRTB As New RichTextBox()
myTabPage.Controls.Add(MyRTB)
MyRTB.Height = RichTextBox1.Height
MyRTB.Width = RichTextBox1.Width
MyRTB.Dock = DockStyle.Fill
End Sub

With this I can just click "New Tab" on my menu and it works perfectly
but whenever I try using anything else regardless of where the code is there are either errors or it doesn't work anything like the way it should, if I click anywhere on the control it adds another tab rather then only when I click my selected "+" tab.
Im not sure why this is so much trouble I mean isn't this very common code? I see the same physical layout all over the place.
Id be very surprised if what I am looking for is any longer then a line or two of code <_<
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Jan 19 2016 09:19pm
Quote (SikGod @ Jan 19 2016 09:20pm)
Thanks for all the help but I have worked on this all day and I cant get any of the examples to work. From my experience that websites worse then useless unless you are a Microsoft tech or have already gone to school for this area though. :(
Code
Private Sub NewTabToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NewTabToolStripMenuItem.Click
Dim myTabPage As New TabPage()
myTabPage.Text = "TabPage" & (Tab2.TabPages.Count + 1)
Tab2.TabPages.Add(myTabPage)
Dim MyRTB As New RichTextBox()
myTabPage.Controls.Add(MyRTB)
MyRTB.Height = RichTextBox1.Height
MyRTB.Width = RichTextBox1.Width
MyRTB.Dock = DockStyle.Fill
End Sub

With this I can just click "New Tab" on my menu and it works perfectly
but whenever I try using anything else regardless of where the code is there are either errors or it doesn't work anything like the way it should, if I click anywhere on the control it adds another tab rather then only when I click my selected "+" tab.
Im not sure why this is so much trouble I mean isn't this very common code? I see the same physical layout all over the place.
Id be very surprised if what I am looking for is any longer then a line or two of code <_<




1: if you are the only one writing the code, then it is doing exactly what you tell it to (in 99.9% of cases)

2: msdn is THE resource. They have some shit documentation for shit you probably don't need to worry about right now, but for stuff like this it WAI. Get used to it honestly.

3: You have not provided all the relevant source yet. You should always do this.

4: As carte suggested, the high level solution to your problem is to handle the tab selected/clicked event (if it exists) then do (x), whatever (x) is.

This post was edited by Eep on Jan 19 2016 09:20pm
Member
Posts: 3,439
Joined: Jan 1 2007
Gold: 128,248.52
Jan 19 2016 09:54pm
Here is one source I still had up since it showed the most promise http://stackoverflow.com/questions/6738126/winforms-tabcontrol-add-new-tab-button the link in the first post explains pretty well what I am looking for with my tabcontrol my project is just different
Code
Private Sub TabControl1_Selected(sender as Object, e as TabControlEventArgs) _
Handles TabControl1.Selected

Dim messageBoxVB as New System.Text.StringBuilder()
messageBoxVB.AppendFormat("{0} = {1}", "TabPage", e.TabPage)
messageBoxVB.AppendLine()
messageBoxVB.AppendFormat("{0} = {1}", "TabPageIndex", e.TabPageIndex)
messageBoxVB.AppendLine()
messageBoxVB.AppendFormat("{0} = {1}", "Action", e.Action)
messageBoxVB.AppendLine()
MessageBox.Show(messageBoxVB.ToString(),"Selected Event")

End Sub

This is the first example given in the msdn link, like you said its a high level solution so maybe I just don't understand it because im not on that level .
Knowing this is an example of "Selected" I would expect to see something like..
Code
Private Sub TabControl1_Selected(sender as Object, e as TabControlEventArgs) _
Handles TabControl1.Selected

if selected.createtab then

'Makes a tab with an anchored richtextbox, this code works fine if used on a button click event for example
Dim myTabPage As New TabPage()
myTabPage.Text = "TabPage" & (Tab2.TabPages.Count + 1)
Tab2.TabPages.Add(myTabPage)
Dim MyRTB As New RichTextBox()
myTabPage.Controls.Add(MyRTB)
MyRTB.Height = RichTextBox1.Height
MyRTB.Width = RichTextBox1.Width
MyRTB.Dock = DockStyle.Fill

end if


And I am not really sure where there example is referencing any particular tab or tab as a variable.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Jan 19 2016 09:58pm
Quote (SikGod @ Jan 19 2016 10:54pm)
Here is one source I still had up since it showed the most promise http://stackoverflow.com/questions/6738126/winforms-tabcontrol-add-new-tab-button the link in the first post explains pretty well what I am looking for with my tabcontrol my project is just different
Code
Private Sub TabControl1_Selected(sender as Object, e as TabControlEventArgs) _
Handles TabControl1.Selected

Dim messageBoxVB as New System.Text.StringBuilder()
messageBoxVB.AppendFormat("{0} = {1}", "TabPage", e.TabPage)
messageBoxVB.AppendLine()
messageBoxVB.AppendFormat("{0} = {1}", "TabPageIndex", e.TabPageIndex)
messageBoxVB.AppendLine()
messageBoxVB.AppendFormat("{0} = {1}", "Action", e.Action)
messageBoxVB.AppendLine()
MessageBox.Show(messageBoxVB.ToString(),"Selected Event")

End Sub

This is the first example given in the msdn link, like you said its a high level solution so maybe I just don't understand it because im not on that level .
Knowing this is an example of "Selected" I would expect to see something like..
Code
Private Sub TabControl1_Selected(sender as Object, e as TabControlEventArgs) _
Handles TabControl1.Selected

if selected.createtab then

'Makes a tab with an anchored richtextbox, this code works fine if used on a button click event for example
Dim myTabPage As New TabPage()
myTabPage.Text = "TabPage" & (Tab2.TabPages.Count + 1)
Tab2.TabPages.Add(myTabPage)
Dim MyRTB As New RichTextBox()
myTabPage.Controls.Add(MyRTB)
MyRTB.Height = RichTextBox1.Height
MyRTB.Width = RichTextBox1.Width
MyRTB.Dock = DockStyle.Fill

end if

And I am not really sure where there example is referencing any particular tab or tab as a variable.


edit:

I still feel like I don't understand 100% what your end goal is here.


Do you have a window, with a tab control, where one of the tabs is labeled "+", that when you click it, it creates a new tab and adds it to the tab control?

This post was edited by Eep on Jan 19 2016 10:15pm
Member
Posts: 3,439
Joined: Jan 1 2007
Gold: 128,248.52
Jan 20 2016 06:22am
Yeah that's pretty much what I am trying to get working similar to how a browser tab control works.
Member
Posts: 15,717
Joined: Aug 20 2007
Gold: 481.00
Jan 20 2016 09:24am
The last example you posted perfectly shows you how to add a tab page to the control and name it
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll