I have 2 Windows Forms.
In first, the main window form, has multiline textbox and a button. The button opens the second form in which I can add data to array by using AddEntry object.
In second form I have textboxes and a button (btnAddEntry) which should update the content of the textbox from first form.
When data is entered I want to display data in textbox from the first form.
The problem is that code I came up with doesn’t seem to work.
How would I solve this?
To get the BASICs working, do the following.. Create a new project. Nothing of your current code, windows, etc… The default project will create a form “Form1” leave it alone for now.
Add a NEW form to the project, it will default to “Form2″… Put a single textbox on it and a single button on it. For grins, and clarification to differentiate between the object names, change the name of the controls on Form2 to “txtOnForm2”, and “btnOnForm2” (case sensitive for my sample, and readability vs “txtonform2” all lower case). Now, on the form, right-click and click “View Code”. It will bring you to the other “Partial class” declaration where your constructors are found. Add the following, dont worry about compile errors as the other half will be when we put code into Form1 next…
Save and close the Form2 designer and code window.
Now, open Form1. Put a single textbox and a single button on it. The default names for the controls will be “textbox1” and “button1” respectively. Leave it as is. Double click on the button (on form1). It will bring up a snippet for code for that button. Paste the following
Now, save the forms and run them. Click button on first form, calls the second with the already created instance of itself, not a new SECOND instance of itself. The second form will be displayed. Shift the windows so you can see both.
Enter some text in the textbox second window and click the button… follow the back/forth of what is coming/going.