TextBox









How do I use Text Box
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: frmCapNhat.cs Copy
38         private void Bandau()
39         {
40             checkBox1.Checked = false;
41             checkBox2.Checked = false;
42             checkBox3.Checked = false;
43             checkBox4.Checked = false;
44             textBox1.Text = "";
45             textBox2.Text = "";
46             textBox3.Text = "";
47             textBox4.Text = "";
48             textBox5.Text = "";
49             richTextBox1.Text = "";
50         }
File name: frmCapNhat.cs Copy
54         private void listView1_SelectedIndexChanged(object sender, EventArgs e)
55         {
56             bool bdapan = false;
57             for (int i = 0; i < listView1.Items.Count; i++)
58             {
59                 if (listView1.Items[i].Selected)
60                 {
61                     textBox5.Text = listView1.Items[i].SubItems[0].Text;
62                     textBox1.Text = listView1.Items[i].SubItems[2].Text;
63                     textBox2.Text = listView1.Items[i].SubItems[3].Text;
64                     textBox3.Text = listView1.Items[i].SubItems[4].Text;
65                     textBox4.Text = listView1.Items[i].SubItems[5].Text;
66                     richTextBox1.Text = listView1.Items[i].SubItems[1].Text;
67                     string t = listView1.Items[i].SubItems[6].Text.ToString().Trim();
68                     if (t.Length >= 2)
69                     {
70                         for (int ii = 0; ii < t.Length; ii++)
71                         {
72                             t2 = t[0].ToString();
73                             if (t[1].ToString() == "")
74                             {
75                                 t1 = "NULL";
76                             }
77                             else
78                             {
79                                 t1 = t[1].ToString();
80                             }
81                         }
82                     }
83                     else
84                     {
85                         t2 = t;
86                         t1 = "NULL";
87                     }
88                     Macdinh();
89                     if (t1 == "A")
90                     {
91                         checkBox1.Checked = true;
92                     }
93                     if (t1 == "B")
94                     {
95                         checkBox2.Checked = true;
96                     }
97                     if (t1 == "C")
98                     {
99                         checkBox3.Checked = true;
100                     }
101                     if (t1 == "D")
102                     {
103                         checkBox4.Checked = true;
104                     }
105
106                     if (t2 == "A")
107                     {
108                         checkBox1.Checked = true;
109                     }
110                     if (t2 == "B")
111                     {
112                         checkBox2.Checked = true;
113                     }
114                     if (t2 == "C")
115                     {
116                         checkBox3.Checked = true;
117                     }
118                     if (t2 == "D")
119                     {
120                         checkBox4.Checked = true;
121                     }
122                     bdapan = true;
123                 }
124                 if (bdapan == false)
125                 {
126                     Bandau();
127                 }
128             }
129
130         }
File name: frmCapNhat.cs Copy
176         private void btLog_Click(object sender, EventArgs e)
177         {
178             Bandau();
179             button4.Enabled = true;
180             textBox5.Text = SDienMaTuDong(textBox1.Text, sqlcmd, sqlcon);
181         }
File name: frmCapNhat.cs Copy
183         private void button1_Click_1(object sender, EventArgs e)
184         {
185             try
186             {
187                 string sCauA = textBox1.Text;
188                 string sCauB = textBox2.Text;
189                 string sCauC = textBox3.Text;
190                 string sCauD = textBox4.Text;
191                 string sMaCH = textBox5.Text;
192                 string sCauHoi = richTextBox1.Text;
193                 string sCauDung = "";
194                 string sCauDungLuu = "";
195                 string sTrinhDo = comboBox1.Text;
196                 if (richTextBox1.Text.ToString().Trim() == "" || textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || (checkBox1.Checked == false && checkBox2.Checked == false && checkBox3.Checked == false && checkBox4.Checked == false))
197                 {
198                     MessageBox.Show("Bạn đã sai làm thao tác", "Thông báo");
199                 }
200                 else
201                 {
202                     if (checkBox1.Checked == true)
203                     {
204                         sCauDung = "A";
205                         sCauDungLuu += sCauDung;
206                     }
207                     if (checkBox2.Checked == true)
208                     {
209                         sCauDung = "B";
210                         sCauDungLuu += sCauDung;
211                     }
212                     if (checkBox3.Checked == true)
213                     {
214                         sCauDung = "C";
215                         sCauDungLuu += sCauDung;
216                     }
217                     if (checkBox4.Checked == true)
218                     {
219                         sCauDung = "D";
220                         sCauDungLuu += sCauDung;
221                     }
222
223                     sqlcmd = new SqlCommand("update dapan set A='" + sCauA + "',B='" + sCauB + "',C='" + sCauC + "',D='" + sCauD + "',dapan='" + sCauDungLuu + "' where mach='" + sMaCH + "'", sqlcon);
224                     sqlcmd.ExecuteNonQuery();
225                     sqlcmd = new SqlCommand("update cauhoi set cauhoi='" + sCauHoi + "', trinhdo='" + sTrinhDo + "' where mach='" + sMaCH + "'", sqlcon);
226                     sqlcmd.ExecuteNonQuery();
227                     LoadDataToListView();
228                     Bandau();
229                 }
230             }
231
232             catch
233             {
234                 MessageBox.Show("Bạn đã sai làm thao tác", "Thông báo");
235             }
236         }
File name: frmCapNhat.cs Copy
238         private void button2_Click(object sender, EventArgs e)
239         {
240             if (richTextBox1.Text == "")
241             {
242                 MessageBox.Show("Vui lòng chọn câu hỏi", "Thông báo");
243             }
244             else
245             {
246                 string sCauHoi = richTextBox1.Text;
247                 if (MessageBox.Show("Bạn có muốn xóa câu hỏi" + " " + sCauHoi, "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
248                 {
249                     string sMaCH = textBox5.Text;
250                     sqlcmd = new SqlCommand("delete cauhoi where mach='" + sMaCH + "'", sqlcon);
251                     sqlcmd.ExecuteNonQuery();
252                     sqlcmd = new SqlCommand("delete dapan where mach='" + sMaCH + "'", sqlcon);
253                     sqlcmd.ExecuteNonQuery();
254                     LoadDataToListView();
255                 }
256                 Bandau();
257             }
258         }
File name: frmCapNhat.cs Copy
311         private void button4_Click(object sender, EventArgs e)
312         {
313             if (richTextBox1.Text == "" || textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || (checkBox1.Checked == false && checkBox2.Checked == false && checkBox3.Checked == false && checkBox4.Checked == false))
314             {
315                 MessageBox.Show("Bạn chưa thêm đầy đủ thông tin", "Thông báo");
316             }
317             else
318             {
319                 try
320                 {
321
322                     string sCauA = textBox1.Text;
323                     string sCauB = textBox2.Text;
324                     string sCauC = textBox3.Text;
325                     string sCauD = textBox4.Text;
326                     string sMaCH = textBox5.Text;
327                     string sCauHoi = richTextBox1.Text;
328                     string sCauDung = "";
329                     string sCauDungLuu = "";
330                     string sTrinhDo = comboBox1.Text;
331                     if (checkBox1.Checked == true)
332                     {
333                         sCauDung = "A";
334                         sCauDungLuu += sCauDung;
335                     }
336                     if (checkBox2.Checked == true)
337                     {
338                         sCauDung = "B";
339                         sCauDungLuu += sCauDung;
340                     }
341                     if (checkBox3.Checked == true)
342                     {
343                         sCauDung = "C";
344                         sCauDungLuu += sCauDung;
345                     }
346                     if (checkBox4.Checked == true)
347                     {
348                         sCauDung = "D";
349                         sCauDungLuu += sCauDung;
350                     }
351
352                     sqlcmd = new SqlCommand("insert into dapan values('" + sMaCH + "','" + sCauA + "','" + sCauB + "','" + sCauC + "','" + sCauD + "','" + sCauDungLuu + "') ", sqlcon);
353                     sqlcmd.ExecuteNonQuery();
354                     sqlcmd = new SqlCommand("insert into cauhoi values('" + sMaCH + "','" + sCauHoi + "','" + sTrinhDo + "') ", sqlcon);
355                     sqlcmd.ExecuteNonQuery();
356                     LoadDataToListView();
357                     button4.Enabled = false;
358                 }
359                 //roi hen;de bi coi lai thu de cHOAky thu chay thu hen ok
360                 catch
361                 {
362                     MessageBox.Show("Bạn đã thao tác sai");
363                 }
364             }
365         }
File name: frmQuanLySinhVien.cs Copy
59         private void btnxoa_Click(object sender, EventArgs e)
60         {
61             sqlcmd = new SqlCommand("delete sinhvien where mats='" + textBox1.Text + "'", sqlcon);
62             sqlcmd.ExecuteNonQuery();
63
64             load();
65         }
File name: frmQuanLySinhVien.cs Copy
67         private void btnthem_Click(object sender, EventArgs e)
68         {
69             try
70             {
71             string mats = textBox1.Text;
72             string hoten = textBox2.Text;
73             string ngaysinh = textBox3.Text;
74             string gioitinh = textBox4.Text;
75             string quequan = textBox5.Text;
76             string sodt = textBox6.Text;
77             string email = textBox7.Text;
78
79             string strSQL = "insert SINHVIEN values('" + mats + "','" + hoten + "','" + ngaysinh + "','" + gioitinh + "','" + quequan + "','" + sodt + "','" + email + "')";
80             sqlcmd = new SqlCommand(strSQL, sqlcon);
81             sqlcmd.ExecuteNonQuery();
82             MessageBox.Show("B?n dã dang ký thành công");
83             load();
84             }
85                 catch
86             {
87                 MessageBox.Show("Trùng mã sinh viên !!!");
88                 }
89
90         }
File name: frmQuanLySinhVien.cs Copy
97         private void btnsua_Click(object sender, EventArgs e)
98         {
99             try
100             {
101                 string mats = textBox1.Text;
102                 string hoten = textBox2.Text;
103                 string ngaysinh = textBox3.Text;
104                 string gioitinh = textBox4.Text;
105                 string quequan = textBox5.Text;
106                 string sodt = textBox6.Text;
107                 string email = textBox7.Text;
108                 sqlcmd = new SqlCommand("update sinhvien set mats='" + mats + "',hoten='" + hoten + "',ngaysinh='" + ngaysinh + "',gioitinh='" + gioitinh + "',quequan='" + quequan + "',sodienthoai='" + sodt + "',email'" + email + "' ", sqlcon);
109                 sqlcmd.ExecuteNonQuery();
110
111                 load();
112             }
113             catch
114             {
115                 MessageBox.Show("Loi");
116             }
117         }
File name: frmQuanLySinhVien.cs Copy
128         private void listView1_SelectedIndexChanged(object sender, EventArgs e)
129         {
130             for (int i = 0; i < listView1.Items.Count; i++)
131                 if (listView1.Items[i].Selected)
132                 {
133                     textBox1.Text = listView1.Items[i].SubItems[0].Text;
134                     textBox2.Text = listView1.Items[i].SubItems[1].Text;
135                     textBox3.Text = listView1.Items[i].SubItems[2].Text;
136                     textBox4.Text = listView1.Items[i].SubItems[3].Text;
137                     textBox5.Text = listView1.Items[i].SubItems[4].Text;
138                     textBox6.Text = listView1.Items[i].SubItems[5].Text;
139                     textBox7.Text = listView1.Items[i].SubItems[6].Text;
140
141                 }
142         }

TextBox 107 lượt xem

Gõ tìm kiếm nhanh...