Formlar arası veri alış verişi, textboxtan diğer formdaki textbox a veri göndermeArkadaşlar Özellikle Form kısmında Bu tip soruların Çokluğundan Kısa bir Açıklama ile Aşağıdaki kodları yazdım.
Sadece iki yol ile yaptım birisi direk erişim Diğer yol ise fonksiyon yardımıyla.
KOLAY GELSİN
Form1 de bir textbox 3 button ekleyin
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace verideneme
{
public partial class Form1 : Form
{
public Form2 frm2=null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (frm2 != null)
frm2.textBox1.Text = this.textBox1.Text;
else
MessageBox.Show("Form Gösterme Tuşuna Basınız");
}
private void button2_Click(object sender, EventArgs e)
{
frm2 = new Form2();
frm2.Show();
}
private void button3_Click(object sender, EventArgs e)
{
if (frm2!=null)
frm2.TextBoxDoldur(textBox1.Text);
else
MessageBox.Show("Form Gösterme Tuşuna Basınız");
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
FORM2 de 1 text box ekleyin ve form2.designer.cs de
private System.Windows.Forms.TextBox textBox1;
şeklindeki kodları
//burada ki public kısmı textbox1 e dışarıdan erişimin sağlanması için önemli
public System.Windows.Forms.TextBox textBox1;
Şekline değiştirin
form2 kodlarıda Aşağıda
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace verideneme
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public void TextBoxDoldur(string txt)
{
textBox1.Text = txt;
}
}
}
SİYAHSERİT