예제 #1
0
 /// <summary>
 /// 加载所有的物料类型
 /// </summary>
 private void CreatBtnByMaterials()
 {
     try
     {
         IList <MaterialInfo> AllMaterials = AGVClientDAccess.LoadAllMaterial();
         if (AllMaterials != null)
         {
             int TotalWidth = this.Width;
             int RowAcount  = TotalWidth / (150 + 5);
             int Amount     = 0;
             int HasWidth   = 0;
             int RowCount   = 1;
             foreach (MaterialInfo MaterialInfo in AllMaterials)
             {
                 Amount++;
                 Button btn = new Button();
                 btn.Tag       = MaterialInfo.MaterialType;
                 btn.Anchor    = AnchorStyles.Left;
                 btn.Text      = MaterialInfo.MaterialName;
                 btn.Click    += Btn_Click;
                 btn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                 btn.FlatAppearance.BorderSize = 0;
                 btn.BackColor = Color.DarkRed;
                 btn.ForeColor = Color.White;
                 btn.Font      = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                 btn.Size      = new System.Drawing.Size(150, 60);
                 if (Amount == 1)
                 {
                     btn.Location = new Point(5, 5);
                     HasWidth     = btn.Width + 5;
                 }
                 else if (Amount <= RowAcount)
                 {
                     btn.Location = new Point(HasWidth + 5, ((RowCount - 1) < 0 ? 0 : RowCount - 1) * btn.Height + (5 * RowCount));
                     HasWidth    += btn.Width + 5;
                 }
                 else
                 {
                     HasWidth     = 0;
                     RowCount    += 1;
                     btn.Location = new Point(HasWidth + 5, ((RowCount - 1) < 0 ? 0 : RowCount - 1) * btn.Height + (5 * RowCount));
                     HasWidth    += btn.Width + 5;
                     Amount       = 1;
                 }
                 this.pnlBtn.Controls.Add(btn);
             }
         }
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }