Printing out text between forms

JohnCTX 636 Reputation points
2021-08-12T23:11:16.493+00:00

I am having too many issues when it comes to popup forms.
What I want to do is to apply text between forms.

Here is the code snippet:
using System;
using System.Windows.Forms;

namespace Source_Code_Assistant_Build_0007  
{  
    public partial class FormTwo : Form  
    {  
         
  
        public FormTwo()  
        {  
            InitializeComponent();  
        }  
  
        private void ApplyDataButton_Click(object sender, EventArgs e)  
        {  
            SourceCodeAssistantForm form = new SourceCodeAssistantForm();  
            SourceCodeTextBox.Text += form.Controls[0].Text;  
  
        }  
  
        private void SourceCodeTextBox_TextChanged(object sender, EventArgs e)  
        {  
              
        }  
    }  
}  

namespace Source_Code_Assistant_Build_0007
{
public partial class SourceCodeAssistantForm : Form
{
FormTwo two;

    public SourceCodeAssistantForm()  
    {  
        InitializeComponent();  
    }  

    private void SourceCodeAssistantForm_Load(object sender, EventArgs e)  
    {  
        FormTwo two = new FormTwo();  
        two.Show();  
          

    }  
}  

}

And here are the forms:

122915-screenshot-2.png

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,596 Reputation points Volunteer Moderator
    2021-08-12T23:34:05.213+00:00

    See the following project on GitHub which is a basic code sample for passing data from child to parent form. A delegate and event are used found here. The parent form subscribes to the event here. In the following method data is received from the child form.

    Many developers do not consider using delegates-events but they can make things very simple once you understand them.

    To pass data from parent to child, create an overloaded constructor for the child form, pass data via this constructor then assign that data to a private variable to be used in say the child form shown event. Alternate is to cast the Owner property of the child form to the type of the parent form but consider there many be cases that will not work when dealing with different scopes of data.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.