I made projects with two forms, and when I click button in Form1 it's OK, text in textbox1 in Form2 is OK, but when I close Form2 and open Form2 second time there isn't text.
Well I didn't download your project, but I'm guessing you're actually closing your Form2 instead of hiding it, which causes the instance of Form2 to disappear and therefore a new one to be created when you open it again. If you're using...
You have a TextBox on Form2 and you want to retain the text that is in it even after the form is closed? Do you want that text to load with the program every time it is run or clear the TextBox when the program is closed?
To have it maintain the text only while the program is running (not after it is closed and re-opened), just declare a global String variable in the main class (Form1) that holds the value of the Textbox and on Form2's Load event, just set the TextBox's Text property to that variable.
To maintain the text between multiple program executions (run it, close it, run it again), you could write that text to a text file, a database, or save it in your My.Settings.
When he closes Form2, it'll clear the TextBox each time though. If the text in the TextBox is dynamic (changes), hard coding it with the AppendText won't be ideal.
He could do something like:
TextBox1.AppendText(myText) 'myText being a global string variable
ok. to make your text persistent in form2, do this:
1/ select your textbox in your design time form
2/ expand (ApplicationSettings) in your properties window
3/ select (PropertyBindings) + click the ellipsis to the right
4/ select the text property in the dialog + click the dropdown arrow to the right
5/ click New in the dropdowm menu + type in a name for the property in the New Application Setting window
6/ click OK on the New Application Setting window
7/ click OK on the Application Settings window
then use this code:
vb Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Thank you for yours answers, but I didn't solve problem.
Maybe I would help you more If I tell you where I would use this.
I need log file. I have, let's say 10 forms in my project, and when I do something in any form I want to put text in some other form (where is it log file), so I want to control text in one form from all other forms in projects.
I hope that's clear now.
i've already said, the easiest way is to declare a Class-level variable in your main form. this gives your whole project (every form) access to the variable and its value.
if you don't understand that, research "class-level variables vb.net" and you will find your answer.