Exemple #1
0
 private void ManualGenerate(int numberofelement)
 {
     deletebuttonnode();
     M = new int[numberofelement];
     for (int i = 0; i < numberofelement; i++)
     {
         int        giaTri = 0;
         ButtonNode temp   = new ButtonNode(i, giaTri);
         this.ViewPanel.Controls.Add(temp);
         nodeArr.Add(temp);
         temp.Location = new Point(ViewPanel.Location.X + i * 80 - 20 * int.Parse(NumberOfElementTxt.Text), ViewPanel.Location.Y - 40 / 2);
         M[i]          = giaTri;
     }
     nodeArr[0].Focus();
 }
Exemple #2
0
        private void backgroundWorker1_ProgressChanged_1(object sender, ProgressChangedEventArgs e) //được thực thi khi gọi hàm ReportProgess()
        {
            //Cập nhật giao diện thời gian thực xong chuyển đến hàm dowork
            Status st = e.UserState as Status;

            if (st == null)
            {
                return;            //không làm gì cả
            }
            //dừng đã làm rồi
            if (st.Type == LoaiDiChuyen.DUNG)//nếu dừng tiến trình thì thay đổi giá trị của 2 nút trong mảng
            {
                ButtonNode tam = nodeArr[st.Vt2];
                nodeArr[st.Vt2] = nodeArr[st.Vt1];
                nodeArr[st.Vt1] = tam;
                return;
            }
            Button btn1 = nodeArr[st.Vt1];
            Button btn2 = nodeArr[st.Vt2];

            if (st.Type == LoaiDiChuyen.DI_LEN_DI_XUONG)
            {
                btn1.Top = btn1.Top + 1; //Nút 1 đi lên
                btn2.Top = btn2.Top - 1; //Nút 2 đi xuống
            }
            else if (st.Type == LoaiDiChuyen.QUA_PHAI_QUA_TRAI)
            {
                btn1.Left = btn1.Left - 1; //nút 1 qa phải
                btn2.Left = btn2.Left + 1; //Nút 2 di chuyển qua trái
            }
            else if (st.Type == LoaiDiChuyen.DI_XUONG_DI_LEN)
            {
                btn1.Top = btn1.Top - 1; //Nút 1 đi xuống
                btn2.Top = btn2.Top + 1; //Nút 2 đi lên
            }
        }