Cách truyền dữ liệu giữa 2 form ppt

2 777 1
Cách truyền dữ liệu giữa 2 form ppt

Đang tải... (xem toàn văn)

Thông tin tài liệu

CÁCH TRUYỀN DỮ LIỆU GIỮA 2 FORM Trước hết chúng ta tạo 2 Form Cách 1: Dùng Constructor Tại Form 2: public Form2(string strTextBox) { InitializeComponent(); textBox1.Text = strTextBox; } Tại Form 1: Click dubble vao button Send Data để viết code cho even Even button1_click private void button1_Click(object sender, EventArgs e) { Form2 fr2 = new Form2(textBox1.Text); fr2.Show(); } Cách 2: Dùng delegate Bước 1: Tại Form 1:  Tạo deligate: public delegate void TruyenTS(TextBox text);  Tại Even button1_click: private void button1_Click(object sender, EventArgs e) { Form2 fr2 = new Form2(); TruyenTS truyen = new TruyenTS(fr2.Data); truyen(textBox1); fr2.Show(); } Bước 2: Tại Form 2: Tạo một hàm delegate đã trỏ tới có nhiệm vụ gán đoạn text cho Textbox1 của Form 2 public void Data(TextBox text) { textBox1.Text = text.Text; } Kết quả: . CÁCH TRUYỀN DỮ LIỆU GIỮA 2 FORM Trước hết chúng ta tạo 2 Form Cách 1: Dùng Constructor Tại Form 2: public Form2 (string strTextBox) { InitializeComponent(); . button1_Click(object sender, EventArgs e) { Form2 fr2 = new Form2 (); TruyenTS truyen = new TruyenTS(fr2.Data); truyen(textBox1); fr2.Show(); } Bước 2: Tại Form 2: Tạo một hàm delegate đã trỏ tới có. } Tại Form 1: Click dubble vao button Send Data để viết code cho even Even button1_click private void button1_Click(object sender, EventArgs e) { Form2 fr2 = new Form2 (textBox1.Text); fr2.Show();

Ngày đăng: 29/07/2014, 08:20

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan