Click here to Skip to main content
15,917,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have created a windows application in which-when the user clicks a button it asks for the tab name using an inputbox. based on the user input, a new form gets created with the tabpage.text property set to the user input.

I am facing 2 problems:confused::confused:

1. I added controls in the button click event to add it to the tabpage. Now How can i save the contents, for ex..i've added code to create a text box to add in the tabpage. How cn i save the textbox's text. I used add handler and gave the address of a sub.but am not able to access the dynamically created textbox.

2.I want to save the tabpages that the user created so that when the next time, the application is run..the tabpages that wer created the last time shud be present. (I tried

Please anyone help me out here. I googled a lot but am not getting a specific answer.Thanx in advance!!

For your first question:

The sub you created for the handler contains 2 parameters (typically called 'sender' and 'e')

The sender param (type object) is your dynamically created textbox so if you cast that one to a textbox you will be able to get the text out of it.

For your second question:

This will require some more work.
You'll have to use serialization for this.
Google it a bit because it's quite complicated to explain in a short post here.
Some links to get you started:
(k that's just weird they worked perfectly at work)

anyway try this link (google search) it has many links to serialization in[^]
Share this answer
VascoDaGama 28-Sep-10 10:12am    
hii Tom,

Thanks for the super duper fast reply. But the links that u sent are all 404 errors.y so??

I thot it was my internet problem and checked out but still not able to open any pages. all of them showing page not found.
Hi Tom,

Thanks for the solution for my first problem. It works perfectly!!

This is what i did (for all those who are haunted with this same problem)

'button click to create dynamically a textbox

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim t As New TextBox
        t.Location = New System.Drawing.Point(84, 56)
        AddHandler t.LostFocus, AddressOf copy
End Sub

'And here is the lostfocus event for the textbox that was created

Protected Sub copy(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim t As TextBox = sender
End Sub

Now I gotta work on the second problem!! Thank you the way for pointing me in the right direction.
Share this answer
Tom Deketelaere 28-Sep-10 12:49pm    
I updated the answer with an new link (the links worked at work but having the same problem as you at home, don't know why but...)
here is the gem you have been looking for. To scope the use of this class. I can be used to save a whole chain of treenodes from the top level node of a treview.

Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary

<Serializable()> Public Class SaveLoad

    Sub WriteFile(ByVal FileName As String, ByVal FileObject As Object)

        Dim ms As MemoryStream = New MemoryStream
        Dim bf As BinaryFormatter = New BinaryFormatter

        bf.Serialize(ms, FileObject)

        File.WriteAllBytes(FileName, ms.ToArray)

    End Sub

    Function ReadFile(ByVal FilePath As String) As Object

        Dim ms As MemoryStream = New MemoryStream(File.ReadAllBytes(FilePath))
        Dim bf As BinaryFormatter = New BinaryFormatter
        Dim FileObject As Object = DirectCast(bf.Deserialize(ms), Object)

        Return FileObject

    End Function

End Class
Share this answer
Thank you sooo much guys-Tom, Henry and Member 3817651506.

Got it working!!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900