using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Casic.Birmm.RbFreqStandMeasure.counter { public partial class CounterCtrlForm : UserControl { DataTable counterResults = null; #region 样式常量定影 private readonly Color titleBackColor = Color.FromArgb(63, 132, 215); // #3F64D7 private readonly Font titleFont = new Font("微软雅黑", 14F, FontStyle.Regular, GraphicsUnit.Pixel, 134); #endregion public CounterCtrlForm() { InitializeComponent(); InitTableCounter(); LoadCounterResultList(); } private void InitTableCounter() { tableCounterResult.Columns.Clear(); tableCounterResult.Rows.Clear(); // 添加标题栏 Panel tableHeader = new Panel { BackColor = Color.White, Size = new Size(714, 50), Location = new Point(0, 0) }; tableHeader.BackColor = titleBackColor; tableCounterResult.Controls.Add(tableHeader); // 序号 Label colIndex = new Label { Font = titleFont, ForeColor = Color.White, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "序号", Location = new Point(0, 0), Size = new Size(50, 50) }; tableCounterResult.Controls.Add(colIndex); colIndex.BringToFront(); // 仪器型号 Label colDevType = new Label { Font = titleFont, ForeColor = Color.White, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "仪器型号", Location = new Point(50, 0), Size = new Size(100, 50) }; tableCounterResult.Controls.Add(colDevType); colDevType.BringToFront(); // 仪器编号 Label colDevNo = new Label { Font = titleFont, ForeColor = Color.White, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "仪器编号", Location = new Point(150, 0), Size = new Size(100, 50) }; tableCounterResult.Controls.Add(colDevNo); colDevNo.BringToFront(); // 描述/端口 Label colDevPort = new Label { Font = titleFont, ForeColor = Color.White, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "描述/端口", Location = new Point(250, 0), Size = new Size(100, 50) }; tableCounterResult.Controls.Add(colDevPort); colDevPort.BringToFront(); // 标称值 Label colStdValue = new Label { Font = titleFont, ForeColor = Color.White, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "标称值", Location = new Point(350, 0), Size = new Size(100, 50) }; tableCounterResult.Controls.Add(colStdValue); colStdValue.BringToFront(); // 指标值 Label colValue = new Label { Font = titleFont, ForeColor = Color.White, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "指标值", Location = new Point(450, 0), Size = new Size(100, 50) }; tableCounterResult.Controls.Add(colValue); colValue.BringToFront(); // 创建日期 Label colCreateTime = new Label { Font = titleFont, ForeColor = Color.White, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "创建日期", Location = new Point(550, 0), Size = new Size(164, 50) }; tableCounterResult.Controls.Add(colCreateTime); colCreateTime.BringToFront(); } private void LoadCounterResultList() { counterResults = new DataTable(); counterResults.Columns.Add("index", Type.GetType("System.String")); counterResults.Columns.Add("devType", Type.GetType("System.String")); counterResults.Columns.Add("devNo", Type.GetType("System.String")); counterResults.Columns.Add("devPort", Type.GetType("System.String")); counterResults.Columns.Add("stdValue", Type.GetType("System.String")); counterResults.Columns.Add("value", Type.GetType("System.String")); counterResults.Columns.Add("createTime", Type.GetType("System.DateTime")); counterResults.Rows.Add("1", "53250A", "123456", "输入A", "10Hz", "12Hz", DateTime.Now); counterResults.Rows.Add("2", "53250A", "123456", "输入A", "10Hz", "12Hz", DateTime.Now); counterResults.Rows.Add("3", "53250A", "123456", "输入A", "10Hz", "12Hz", DateTime.Now); counterResults.Rows.Add("4", "53250A", "123456", "输入A", "10Hz", "12Hz", DateTime.Now); counterResults.Rows.Add("5", "53250A", "123456", "输入A", "10Hz", "12Hz", DateTime.Now); tableCounterResult.DataSource = counterResults; // width=714px tableCounterResult.Columns[0].Width = 50; tableCounterResult.Columns[1].Width = 100; tableCounterResult.Columns[2].Width = 100; tableCounterResult.Columns[3].Width = 100; tableCounterResult.Columns[4].Width = 100; tableCounterResult.Columns[5].Width = 100; tableCounterResult.Columns[6].Width = 164; tableCounterResult.Columns[0].ReadOnly = true; tableCounterResult.Columns[1].ReadOnly = true; tableCounterResult.Columns[2].ReadOnly = true; tableCounterResult.Columns[3].ReadOnly = true; tableCounterResult.Columns[4].ReadOnly = true; tableCounterResult.Columns[5].ReadOnly = true; tableCounterResult.Columns[6].ReadOnly = true; } } }