public void RefreshPanel2(调试模块 tmp) { Control [] c = MainModelPanel_1.Controls.Find("模块" + tmp.模块编号.ToString(), false); if (c != null && c.Count() != 0 && c[0] is MainModelPanel) { MainModelPanel mainModelPanel = (c[0] as MainModelPanel); mainModelPanel.RefreshPanel(tmp.模块编号, tmp.模块类型, tmp.State, tmp.FalutState); } }
public void PanelLayout(int setWitdh = 200, int setHeight = 140, int count = 16) { for (int t = 0; t < MainModelPanel_1.Controls.Count;) { if (MainModelPanel_1.Controls[t] is MainModelPanel) { MainModelPanel_1.Controls.Remove(MainModelPanel_1.Controls[t] as MainModelPanel); } else { t++; } } int initSetWitdh = setWitdh; int initSetHeight = setHeight; int cols = MainModelPanel_1.Width / setWitdh; //int rows = MainModelPanel_1.Height / setHeight; int rows = (count % cols) == 0? (count / cols): (count / cols) + 1; //rows = MainModelPanel_1.Height / setHeight; bool b = true; //while (true) //{ // if (cols * rows < count) // { // //if (MainModelPanel.Height < rows * setHeight) // // MainModelPanel.Height = rows * setHeight; // //if(MainModelPanel.Width < cols * setWitdh) // // MainModelPanel.Width = cols * setWitdh; // if (b) // { // //setWitdh = (int)(setWitdh - setWitdh * 0.1); // //setHeight = (int)(setHeight - setHeight * 0.1); // setWitdh = (int)(setWitdh - 0); // setHeight = (int)(setHeight - 0); // cols = MainModelPanel_1.Width / setWitdh; // } // if (setWitdh < initSetWitdh * 0.5) // { // b = false; // rows++; // } // } // else // break; //} //MainModelPanel.Height += 30; int xmargin = (MainModelPanel_1.Width - setWitdh * cols) / 3; //int ymargin = 30; //int ymargin = (MainModelPanel.Height - setHeight * rows) / 2; int tmpCount = 0; int i; for (i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { if (tmpCount < count) { int w = (int)(setWitdh); int l = (int)(setHeight); MainModelPanel tmp1 = new MainModelPanel(w, l, ModelsOperate.ModelsList[tmpCount].模块编号, ModelsOperate.ModelsList[tmpCount].模块类型, ModelsOperate.ModelsList[tmpCount].State); tmp1.ButtonClick += new ValuEventHandler(MainPanel_Click); tmp1.Location = new Point((int)(xmargin + setWitdh * j), (int)(setHeight * i)); MainModelPanel_1.Controls.Add(tmp1); tmpCount++; } } } }