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

[1084 byte] By [AdrianFoot] at [2007-12-24]
# 1

Ok - I've tried the following code (and played around for a bit) but no joy. Any ideas?

Dim tmpCallsign As String

tmpCallsign = "EGTT_CTR"

TabControl1.TabPages.Add(tmpCallsign)

Dim Text1 As New TextBox

Text1.Parent = TabControl1.TabPages(tmpCallsign)

Text1.Dock = DockStyle.Fill

Text1.Multiline = True

Text1.ScrollBars = ScrollBars.Vertical

Me.Controls.Add(Text1)

AdrianFoot at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

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)

ReneeC at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

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)

ReneeC at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4

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

ReneeC at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5

Excellent, thanks!

And what about deleting it? This is the next thing I'm trying and I can't get it to work haha!

Ady

AdrianFoot at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 6

I've managed to do it, thanks for your help.

Ady

AdrianFoot at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 7

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 !!!!!!!

ReneeC at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...