private void Frmdiepshebei_load ()
{
width = Panel2. WIDTH/15; Panel width
Timer1. Interval = Dp.getboardtime ();
AddButton ("", "in use", Panel2, "Longhua plant");
}
private void AddButton (String strdept, String strstate, Panel p, string strfname)
{
P.controls.clear ();
Blist. Clear ();
st = Dp.getcolorshebei ();
DataTable Dtgree = St. Tables[0];
DataTable dtred = St. TABLES[1];
DT = Dp.getshebei (strdept, Strstate, strFName);
if (strstate = = "normal")
{
DataTable DT2 = Dp.getshebei (strdept, "in use", strfname);
for (int i = 0; i < DT2. Rows.Count; i++)
{
Dt. ImportRow (DT2. Rows[i]);
}
}
Button[] bn = new BUTTON[DT. Rows.Count];
int x = 50;
int y = 0;
for (int i = 0; i < dt. Rows.Count; i++)
{
Bn[i] = new Button ();
Bn[i]. Name = i.ToString ();
Bn[i]. Text = dt. Rows[i][0]. ToString ();
Bn[i]. Font = new System.Drawing.Font ("Arial", fontstyle.regular);
Bn[i]. Size = new System.Drawing.Size (width, height);
x = (width + +) * (i% 12);
Bn[i]. Location = new Point (x, y);
if ((i + 1)% = = 0 && i! = 0)
{
y = (height + y) + 20;
}
In use
if (strstate = = "in use")
{
Bn[i]. BackColor = Color.dodgerblue;
Determine deactivation
for (int yw = 0; yw < dtGree.Rows.Count; yw++)
{
if (Bn[i]. Text = = dtgree.rows[yw]["Jicode"]. ToString ())
{
Device background color is green
Bn[i]. BackColor = Color.green;
Break
}
}
Determine if it is in service
for (int r = 0; r < DtRed.Rows.Count; r++)
{
if (Bn[i]. Text = = dtred.rows[r]["Jicode"]. ToString ())
{
Device background color is red
Bn[i]. BackColor = color.red;
Blist. ADD (Bn[i]);
Break
}
}
}
Bn[i]. FlatStyle = System.Windows.Forms.FlatStyle.Flat;
Bn[i]. MouseHover + = new System.EventHandler (this.buttonall_mousehove);
P.controls.add (Bn[i]);
}
#region Traverse all the buttons on the form to add to the Blist collection
Traverse all controls on a form
foreach (System.Windows.Forms.Control Control in this.) Controls)
//{
If (Control is System.Windows.Forms.Button)
// {
System.Windows.Forms.Button btn = (System.Windows.Forms.Button) control;
if (btn. Name! = "Button3" && btn. BackColor = = color.red)
// {
Blist. ADD (BTN);
// }
// }
//}
#endregion
}
Auto-generate button position control