save the settings to my form project

BIG BEN

Member
Joined
Jul 6, 2013
Messages
9
Programming Experience
1-3
Hello. I need help. I want to save the settings when I add a new tab page. When I the application run and then press the add button I add a new tab. But when I the aplicattion close, the new tab page disappears. How can I that save to my form project?
 
You can't save it to your form project because, once you've deployed the application, the project doesn't exist. You're deploying a compiled EXE and that's not changing.

What you need to do is save the data external to the application, in a text or XML file or whatever, and then read that data in each time you run the app. The best way to save the data depends on exactly what you want to save. If it's just the number of tabs then you can simply save an Integer in My.Settings. If you need the tab names then you can still use My.Settings and store the data in a StringCollection. If what you need is more complex then maybe serialising one or more instances of a dedicated class is the answer. We can only speculate until you give us a FULL and CLEAR description of exactly what you want though.
 
Ok, her is what i mean. I have a tab controler. Next do him is a add button. When I click that button, automatically he add a tab new page.
this is the code.
Dim tabPage As New TabPage
tabPage.Text = "new tab"
TabControl1.TabPages.Add(tabPage)

and now, I publish the application, and install her.
I open the application, add new tabs pages with add button, close the application. And open it again, and the pages are gone.
 
Yes, so... now is when you tell us exactly what it is that you want to save between sessions. I suggested that it might be:

1. just the number of tabs
2. the names of the tabs
3. something more complex

It's for you to decide which of those you want, not us. Is it 1, 2 or 3 and, if it's 3, exactly what is the more complex data that you want to save?
 
It is 1,2. But also buttons and pictures in a tab page.
You're kidding, right? You say that it's buttons and pictures. Is buttons and pictures just the number of tabs? No it's not, so it's not option 1. Is buttons and pictures the names of the tabs? No it's not, so it's not option 2. Obviously buttons and pictures is more complex than both options 1 and 2 so obviously it's option 3.
jmcilhinney said:
We can only speculate until you give us a FULL and CLEAR description of exactly what you want though.
You are yet to do that. "buttons and pictures in a tab page" is still very vague. Is it the same number of controls in the same locations every time? Do some parts vary? Do all parts vary? We're not going to guess this stuff. You're the only one who knows your project so you have to explain it to us.
 
Firstly, it can't be 1 and 2. Option 1 is "just the number of tabs". If you need to save the names of the tabs, which is option 2, then you're not saving JUST the number. If you save the names of the tabs then you inherently have the number because, for instance, three names means three tabs. So, are you saying that, at the end of a session, you want to save the names of all the tabs you have open and then, when you run the app next time, open up tabs with the same names and that there is NO MORE information that you need to save?
 
OK then. Open the Settings page of the project properties and add a setting of type StringCollection. Open the editor, add an item, click OK, open the editor again and delete the item. Note that the Value field of the setting now contains some XML code, which is what gets stored in the config file. If you named the setting TabNames, you can access it in code via My.Settings.TabNames.

When you load your form, loop through the String Collection and, for each item, add a TabPage with that name. When you close the form, Clear the StringCollection and then Add an item for each TabPage currently open.
 
Thanks man.
Have can I connect two forms. I will use tabcontrol from form1 and textbox from2. When I add a tab page, then opens form2 with textbox.
Code from the form2 is tabpage1.text=textbox.text.
The error is "reference to a non shared member requires an object reference".
 
The specific reason for that error message is that you are using TextBox, i.e. the class, instead of a reference to a specific TextBox object.

It's not a matter of connecting two forms. Forms are objects, just like any other. You create them and get data into and out of them just like any other objects. The correct way to do this is to add a property to your dialogue form that exposes the Text of the TextBox, e.g.
Public ReadOnly Property TextBoxText() As String
    Get
        Return Me.TextBox1.Text
    End Get
End Property
You then create and display the dialogue and, if the user clicks OK, you get the value of that property and use it in the TabPage, e.g.
Using dialogue As New Form2
    If dialogue.ShowDialog() = DialogResult.OK Then
        Me.TabControl1.TabPages.Add(dialogue.TextBoxText)
    End If
End Using
 
As I stated in my previous post, the first code snippet goes in the dialogue form. It should be fairly clear, given that the code refers to a TextBox, that it goes in the form with the TextBox. The other code snippet refers to the TabControl because it goes in the form with the TabControl.
 
I'm afraid you did not understand me. When I add a tab page with my add buton, opens a another form, or form2, never mind. Im form 2 I have a textbox1, and a button. With this textbox a will rename a tab page which is in form 1.
 
Back
Top