Form1'den Form2'ye Form1'in kendisini "this" ile parametre olarak geçip, Form2'nin constructor'unda Form1'e işaret eden değişkeni kullanarak Form2 kapandığında Form1'deki textbox'da Form2'nin textbox değerini görüyoruz. Full kod:
//Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private **** Form1_Load(object sender, EventArgs e)
{
Form2 myform2 = new Form2(this);
myform2.Show();
}
}
}
//Form2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form2 : Form
{
private Form1 x;
public Form2(Form1 x)
{
InitializeComponent();
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.form_closing);
this.x = x;
}
private **** form_closing(object sender, System.Windows.Forms.FormClosingEventArgs e)
{
x.textBox1.Text = this.textBox1.Text;
}
}
}
FormClosing olayı ile Form2 kapanmadan Form1'deki Textbox'a erişebiliyoruz.
İyi çalışmalar,