Dynamic tabs and messages
Hi everyone,
I have a dialog box set up that has several tabs on it. This is a communications dialog box which handles incoming messages across my TCP/IP connection with a server. These messages can be related to different things, for example, and each tab on my dialog box is a representation of these different message types.
Each tab contains a text box and my messaging function writes incoming messages to the text box. That bit is easy; done.
One of the messaging functions that I want to implement is the ability to initialise outgoing messages to other users connected to the servers. Now I know how to do that as far as the network programming goes, it's easy. But I want people to be able to initialise messages with as many people as they need. Now each new message requires a dynamic tab to be created (and thus a dynamic text box) on our communications dialog. This I do not know how to do.
Other considerations are how I reference this tab and text box from my function?
Any help would be much appreciated!
Regards,
Ady
Ok - I've tried the following code (and played around for a bit) but no joy. Any ideas?
Dim
tmpCallsign As StringtmpCallsign =
"EGTT_CTR"TabControl1.TabPages.Add(tmpCallsign)
Dim Text1 As New TextBoxText1.Parent = TabControl1.TabPages(tmpCallsign)
Text1.Dock = DockStyle.Fill
Text1.Multiline =
TrueText1.ScrollBars = ScrollBars.Vertical
Me.Controls.Add(Text1)I'd do this a little differently (typed for memory)
Public Class Tabp
Protected t a new tabpage
Public Sub New(byval Name as string)
t = new TabPage
t.Name = Name
end Sub
Public Sub New()
t = new TabPage
end Sub
Public Function GetTabPage() as tabpage
Return t
end function
End Class
Then in your main code you do this:
Dim A as new Tabp("foo")
TabControl1.tabpages.add(A.GetTabPage)
Sorry I missed the textbox part. You may need to touch this up a bit but I think you get the general idea
I'd do this a little differently (typed for memory)
Public Class Tabp
Protected t as new tabpage
Protected Friend with events tb ' Textbox can now have events
Public Sub New(byval Name as string)
t = new TabPage
t.Name = Name
end Sub
Public Sub New()
t = new TabPage
end Sub
Private Sub DealWithTextBox()
tb = new Textbox
tb.location = new point (10,10)
tb.size = new size (200,100)
tb.multiline = true
tb.scrollbars = textbox1.ScrollBars=ScrollBars.Vertical
end Sub
Public Sub WriteToTb(byval Instr as string)
tb.text = instr
end Sub
Public Sub AppendToTb(byval Instr as string)
tb.text = tb.text & vbcrlf & instr
end Sub
Public Sub ClearTextBox()
TB.Clear()
End Sub
Public Function ReadFromTextBox() as string
Return tb.text
end function
Public Function GetTabPage() as tabpage
Return t
end function
End Class
Then in your main code you do this:
Dim A as new Tabp("foo")
TabControl1.tabpages.add(A.GetTabPage)
Of Course the overloaded New routines should
Public Sub New(byval Name as string)
t = new TabPage
t.Name = Name
DealWithTextBox
end Sub
Public Sub New()
t = new TabPage
DealWithtextbox
end Sub
There are lots of additional tricks.
for example
Dim a as new tabp("foo")
tabcontrol1.tabpages.add(a)
tabcontrol.tabpages(tabcontrol.tabpages.count-1).tag = a
That will store the class in the tag. To find the class all you have to do is to walk the tabs and reading the tabpagename
It's really a lot of fun.
Of course to delete the class
For each p as tabpage in tabcontrol1.tabpages
if p.name = "foo" then
TabControl1.tabpages.remove(p)
p.tag = nothing
p.dispose
exit for
end if
next
voila !!!!!!!