• 自动生成按钮位置控制


    private void FrmdiepSheBei_Load()
    {
      width = panel2.Width / 15;  ////面板宽度
      timer1.Interval = dp.getboardTime();
      addButton("", "在用", panel2, "龙华厂"); 
    }

    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 == "正常")
    {
    DataTable dt2 = dp.getSheBei(strDept, "在用", 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("宋体", 25, FontStyle.Regular);
    bn[i].Size = new System.Drawing.Size(width, height);

    x = (width + 18) * (i % 12);
    bn[i].Location = new Point(x, y);

    if ((i + 1) % 12 == 0 && i != 0)
    {
    y = (height + y) + 20;
    }
    ///在用
    if (strState == "在用")
    {

    bn[i].BackColor = Color.DodgerBlue;

    //判断停用
    for (int yw = 0; yw < dtGree.Rows.Count; yw++)
    {
    if (bn[i].Text == dtGree.Rows[yw]["jiCode"].ToString())
    {
    //设备背景色为绿色
    bn[i].BackColor = Color.Green;
    break;
    }
    }
    //判断是否为维修中
    for (int r = 0; r < dtRed.Rows.Count; r++)
    {
    if (bn[i].Text == dtRed.Rows[r]["jiCode"].ToString())
    {
    //设备背景色为红色
    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 遍历窗体上的所有Button 添加到blist 集合中
    //遍历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

    }

  • 相关阅读:
    算法学习笔记: 珂朵莉树
    算法学习笔记:2SAT
    0x62 图论最小生成树
    Codeforces Round #632 (Div. 2) C. Eugene and an array(尺取法/前缀和)
    BZOJ1912 异象石(LCA/DFS序/set)
    (六1)Firefox插件安装
    (六2)八种定位方式为了查找元素
    (六3)从查找元素到操作元素
    【OSI】网络协议模型
    读《Wireshark网络分析就这么简单》读书笔记
  • 原文地址:https://www.cnblogs.com/VictorBlog/p/5193309.html
Copyright © 2020-2023  润新知