public Panel GetPanel(string name, string quantity, Color foreColor, Color backColor) { Panel panel = new Panel(); panel.Dock = DockStyle.Top; panel.Height = (int)LabelFont.GetHeight() + 2; panel.BackColor = backColor; panel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; Label lblName = new Label(); lblName.AutoSize = false; lblName.ForeColor = foreColor; lblName.Text = name; lblName.Dock = DockStyle.Fill; lblName.Font = LabelFont; lblName.BorderStyle = LabelBorderStyle; Label lblQuantity = new Label(); lblQuantity.AutoSize = false; lblQuantity.ForeColor = foreColor; lblQuantity.Text = quantity; lblQuantity.Dock = DockStyle.Right; lblQuantity.Font = LabelFont; lblQuantity.Width = this.Width / 2; lblQuantity.BorderStyle = LabelBorderStyle; panel.Controls.Add(lblQuantity); panel.Controls.Add(lblName); return(panel); }
public void AddPanel(DsRecord dsRecord) { Panel panel = new Panel(); panel.Height = (int)LabelFont.GetHeight() + 2; panel.BackColor = this.BackColor; panel.Dock = DockStyle.Top; panel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; if (dsRecord.MaterialName == "水" || dsRecord.MaterialName == "间隔水" || dsRecord.MaterialName == "清洗水") { oWater += dsRecord.DSQuantity; } else { oMaterial += dsRecord.DSQuantity; } Label labelNum = new Label(); labelNum.AutoSize = false; labelNum.ForeColor = LabelForeColor; panelCount++; labelNum.Text = panelCount.ToString(); labelNum.TextAlign = ContentAlignment.MiddleRight; labelNum.Dock = DockStyle.Right; labelNum.Font = LabelFont; labelNum.BorderStyle = LabelBorderStyle; labelNum.Width = 50; panel.Controls.Add(labelNum); int[] labelWidth = new int[] { 120, 120, 120, this.Width - 400 }; string[] ls = new string[] { dsRecord.ActionName, dsRecord.MaterialName, dsRecord.DSQuantity.ToString("0.00"), dsRecord.EntryDate }; for (int i = 0; i < ls.Length; i++) { Label label = new Label(); label.AutoSize = false; label.ForeColor = LabelForeColor; label.Text = ls[i]; label.Dock = DockStyle.Right; label.Font = LabelFont; label.BorderStyle = LabelBorderStyle; label.Width = labelWidth[i]; panel.Controls.Add(label); } this.Controls.Add(panel); panel.BringToFront(); this.Invalidate(); }