1

I already sent the data of the textbox in the label that is in another form but what I want is, I want to click that button again then send the result to another label.

this is my code

Form 1's code - this is the receiver

public partial class Form1 : Form
{

    public string IDD { get; set; }
    public string CN { get; set; }
    public string ADD { get; set; }
    public string TIME { get; set; }

    
  
    public Form1()
    {
        InitializeComponent();
        
    }

 private void Form1_Load(object sender, EventArgs e)
    {
        ClientID.Text = IDD;
        ClientName.Text = CN;
        ClientAdd.Text = ADD;
        ClientTime.Text = TIME;

        

    }

Form 2's code - this is the sender

private void btnBack_Click(object sender, EventArgs e)
    {

     
      
        Form1 frm1 = new Form1();

        frm1.IDD = txtID.Text;
        frm1.CN = txtCN.Text;
        frm1.ADD = txtAdd.Text;
        frm1.TIME = dateTimePicker1.Text;
        
        frm1.ShowDialog();

       
       

     
        
       
        
    }
  • Where is `Form2` open?... Is `Form1` opening `Form2` … ? ... the name of the button click event is suspicious… `btnBack` … this makes me think that `Form1` may “already” be open. If this is the case… then `Form2` is “creating” a new one. I am guessing, as it is not clear, where `Form2` is opened and if `Form1` already exist and is already displayed when the code in the `btnBack` is executed. – JohnG Jan 18 '22 at 16:05
  • btnback is the name of the button so when i press btnback, the code will be executed then go to form 1 – Kuga Terunori Jan 18 '22 at 16:08
  • Does `Form1` already exist and is open BEFORE the code in the `btnBack` is executed ... ? ... And "where" is the code that shows `Form2`? – JohnG Jan 18 '22 at 16:11
  • Does this answer your question? [Communicate between two windows forms in C#](https://stackoverflow.com/questions/1665533/communicate-between-two-windows-forms-in-c-sharp) – JohnG Jan 18 '22 at 16:18
  • @JohnG thank you but it didn't – Kuga Terunori Jan 19 '22 at 10:52
  • Well, I feel it actually will help, however if it does not… can you at lease answer my previous questions? I am trying to help, however if you ignore your helpers’ questions, then it is not going to help anyone. To summarize my question, when the button is clicked in form 2… AND BEFORE the code executes… does a `Form1` window “already” exist? It is a simple yes/no question. The point is that it looks “suspicious” to execute… `Form1 frm1 = new Form1();` … when your question text claims it wants to “send” data “Back” to an already existing form. I mean the name of the button IS `btnBack`! – JohnG Jan 19 '22 at 11:10
  • It is important as to which form is “opening” which form. Does `Form1` open `Form2`? If it does, then I am confident that you do NOT want to execute `Form1 frm1 = new Form1();` to “send” data “back” to `Form1`. To do what you describe… the answer is in the duplicate link. – JohnG Jan 19 '22 at 11:12

1 Answers1

0

You can do this by initializing parameterized constructors and holding them in auto-implemented properties.

Assay Khan
  • 56
  • 9
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 18 '22 at 18:36