void init_noicau() { clear_all(); BaiHoc bh = lay_baihoc(); if (bh == null) { return; } List <Cau> trai = new List <Cau>(); List <Cau> phai = new List <Cau>(); Random ranDong = new Random(); List <Noidung> listCau = bh.baihoc; sotu = listCau.Count; lblBai.Text = MyFunction.ConvertUNI2TCV(bh.tieude); int i = 0; while (listCau.Count > 0) { int dong = ranDong.Next(0, listCau.Count); string strNoidung = bh.baihoc[dong].noidung; string[] s = strNoidung.Split(new[] { "//" }, StringSplitOptions.None); trai.Add(new Cau() { id = bh.baihoc[dong].dong, noidung = s[0] }); phai.Add(new Cau() { id = bh.baihoc[dong].dong, noidung = s[1] }); listCau.RemoveAt(dong); i++; } ve_trai(trai); ve_phai(phai); }
void init_box() { int x = le_trai; int y = le_trai; int w = rong + 10; int h = cao + 10; foreach (Noidung dong in baihocTV.baihoc) { int i = 0; foreach (string str in dong.noidung.Split(' ')) { if (x == le_trai && i > 0) { y = y + h + 5; } Label label = new Label(); label.Name = "myLblCtr_Box_" + dong.dong + "_" + i; label.Text = ""; label.Tag = MyFunction.ConvertUNI2TCV(str); label.Width = w; label.Height = h; label.BackColor = box_bcolor; label.Location = new Point(x, y); label.AutoSize = false; label.TextAlign = ContentAlignment.MiddleCenter; label.BorderStyle = BorderStyle.Fixed3D; this.panel1.Controls.Add(label); x += w + 10; if (x > panel1.Width - w) { x = le_trai; } i++; } y = y + h + 15; x = le_trai; } }
void ve_trai(List <Cau> cau) { int x = pnMain.Width / 2 - rong - 100; int y = (pnMain.Height - cau.Count * cao - 20) / 2 - 50; Random rdDong = new Random(); while (cau.Count > 0) { int idx = rdDong.Next(0, cau.Count); idx = rdDong.Next(0, cau.Count); Label lb = new Label(); lb.Text = MyFunction.ConvertUNI2TCV(cau[idx].noidung); lb.Tag = cau[idx].id; lb.Name = "myLblTrai"; lb.Font = new Font(".VnAvant", 20, FontStyle.Bold); lb.BackColor = Color.Aquamarine; lb.BorderStyle = BorderStyle.FixedSingle; lb.AutoSize = false; lb.Width = rong; lb.Height = cao; lb.TextAlign = ContentAlignment.MiddleCenter; lb.Cursor = Cursors.Hand; Point p = new Point(x, y); lb.Location = p; lb.MouseDown += button_MouseDown; lb.MouseUp += button_MouseUp; pnMain.Controls.Add(lb); y = y + cao + 20; cau.RemoveAt(idx); } }
private void init_Tu() { int_all(); Random randomX = new Random(); Random randomY = new Random(); int Y = this.Height / 2; int X = 0; listCtr_Tu = new List <Label>(); List <string> listTu = new List <string>(); lblBai.Text = MyFunction.ConvertUNI2TCV(baihocTV.tieude); txtBai.Text = ""; foreach (Noidung nd in baihocTV.baihoc) { txtBai.Text += MyFunction.ConvertUNI2TCV(nd.noidung) + Environment.NewLine; foreach (string str in nd.noidung.Split(' ')) { listTu.Add(str); } } int sotu = listTu.Count; int sotu_motdong = (this.panel1.Width - le_trai) / (rong + 5); int sodong = (int)Math.Ceiling((double)sotu / (double)sotu_motdong); int vY = panel1.Height - sodong * (cao + 5); List <Point> vitri_Tu = new List <Point>(); for (int i = 0; i < sodong; i++) { vitri_Tu.Add(new Point(le_trai, vY)); vY = vY + cao + 5; } int idxCnt = 0; while (listTu.Count > 0) { Random randomTu = new Random(); int randomIndex = randomTu.Next(0, listTu.Count); Random randomDong = new Random(); int dong = randomDong.Next(0, vitri_Tu.Count); Point p = vitri_Tu[dong]; Label l = new Label(); l.Name = "myLblCtr_Tu" + idxCnt; l.Text = MyFunction.ConvertUNI2TCV(listTu[randomIndex]); l.Font = new Font(".VnAvant", 26, FontStyle.Bold); //l.Font = new Font(MyFunction.myfonts.Families[0],20, FontStyle.Bold); //l.UseCompatibleTextRendering = true; l.BackColor = init_color(); l.BorderStyle = BorderStyle.FixedSingle; //l.ForeColor = Color.Yellow; l.AutoSize = false; l.Width = rong; l.Height = cao; l.TextAlign = ContentAlignment.MiddleCenter; l.Cursor = Cursors.Hand; l.BringToFront(); l.Location = p; l.MouseMove += LOnMouseMove; l.MouseDown += LOnMouseDown; l.MouseUp += LOnMouseUp; this.panel1.Controls.Add(l); listCtr_Tu.Add(l); idxCnt++; listTu.RemoveAt(randomIndex); p.X = p.X + (rong + 5); if (p.X > panel1.Width - (rong + 5)) { vitri_Tu.RemoveAt(dong); } else { vitri_Tu[dong] = p; } } }