Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Cách truyền dữ liệu giữa 2 form ppt
Nội dung xem thử
Mô tả chi tiết
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();