diff --git a/WindowsFormsApp6/MainForm.Designer.cs b/WindowsFormsApp6/MainForm.Designer.cs index bc63a47..d2e7b97 100644 --- a/WindowsFormsApp6/MainForm.Designer.cs +++ b/WindowsFormsApp6/MainForm.Designer.cs @@ -21,10 +21,6 @@ namespace WindowsFormsApp6 private void InitializeComponent() { this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - this.panelTop = new System.Windows.Forms.Panel(); - this.label2 = new System.Windows.Forms.Label(); - this.button1 = new System.Windows.Forms.Button(); - this.comboBox1 = new System.Windows.Forms.ComboBox(); this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.panelTitle = new System.Windows.Forms.Panel(); this.label1 = new System.Windows.Forms.Label(); @@ -55,7 +51,6 @@ namespace WindowsFormsApp6 this.buttonPrint = new System.Windows.Forms.Button(); this.buttonToggleLayout = new System.Windows.Forms.Button(); this.tableLayoutPanel1.SuspendLayout(); - this.panelTop.SuspendLayout(); this.tableLayoutPanel2.SuspendLayout(); this.panelTitle.SuspendLayout(); this.panelInfo.SuspendLayout(); @@ -67,73 +62,19 @@ namespace WindowsFormsApp6 // this.tableLayoutPanel1.ColumnCount = 1; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel1.Controls.Add(this.panelTop, 0, 0); - this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel2, 0, 1); - this.tableLayoutPanel1.Controls.Add(this.tabControl1, 0, 2); - this.tableLayoutPanel1.Controls.Add(this.panelBottom, 0, 3); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel2, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.tabControl1, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.panelBottom, 0, 2); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; - this.tableLayoutPanel1.RowCount = 4; - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 80F)); + this.tableLayoutPanel1.RowCount = 3; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 120F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 80F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(1200, 800); this.tableLayoutPanel1.TabIndex = 0; // - // panelTop - // - this.panelTop.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(52)))), ((int)(((byte)(152)))), ((int)(((byte)(219))))); - this.panelTop.Controls.Add(this.label2); - this.panelTop.Controls.Add(this.button1); - this.panelTop.Controls.Add(this.comboBox1); - this.panelTop.Dock = System.Windows.Forms.DockStyle.Fill; - this.panelTop.Location = new System.Drawing.Point(3, 3); - this.panelTop.Name = "panelTop"; - this.panelTop.Padding = new System.Windows.Forms.Padding(20, 15, 20, 15); - this.panelTop.Size = new System.Drawing.Size(1194, 74); - this.panelTop.TabIndex = 0; - // - // label2 - // - this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.label2.AutoSize = true; - this.label2.Font = new System.Drawing.Font("微软雅黑", 10F); - this.label2.ForeColor = System.Drawing.Color.White; - this.label2.Location = new System.Drawing.Point(950, 27); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(78, 23); - this.label2.TabIndex = 3; - this.label2.Text = "日期时间"; - // - // button1 - // - this.button1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(46)))), ((int)(((byte)(204)))), ((int)(((byte)(113))))); - this.button1.FlatAppearance.BorderSize = 0; - this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.button1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Bold); - this.button1.ForeColor = System.Drawing.Color.White; - this.button1.Location = new System.Drawing.Point(189, 18); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(140, 38); - this.button1.TabIndex = 2; - this.button1.Text = "🔗 连接设备"; - this.button1.UseVisualStyleBackColor = false; - // - // comboBox1 - // - this.comboBox1.BackColor = System.Drawing.Color.White; - this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.comboBox1.Font = new System.Drawing.Font("微软雅黑", 9F); - this.comboBox1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(52)))), ((int)(((byte)(73)))), ((int)(((byte)(94))))); - this.comboBox1.FormattingEnabled = true; - this.comboBox1.Location = new System.Drawing.Point(19, 23); - this.comboBox1.Name = "comboBox1"; - this.comboBox1.Size = new System.Drawing.Size(160, 28); - this.comboBox1.TabIndex = 1; - // // tableLayoutPanel2 // this.tableLayoutPanel2.ColumnCount = 1; @@ -141,7 +82,7 @@ namespace WindowsFormsApp6 this.tableLayoutPanel2.Controls.Add(this.panelTitle, 0, 0); this.tableLayoutPanel2.Controls.Add(this.panelInfo, 0, 1); this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill; - this.tableLayoutPanel2.Location = new System.Drawing.Point(3, 83); + this.tableLayoutPanel2.Location = new System.Drawing.Point(3, 3); this.tableLayoutPanel2.Name = "tableLayoutPanel2"; this.tableLayoutPanel2.RowCount = 2; this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 36F)); @@ -196,6 +137,7 @@ namespace WindowsFormsApp6 this.panelInfo.Padding = new System.Windows.Forms.Padding(20, 10, 20, 10); this.panelInfo.Size = new System.Drawing.Size(1188, 72); this.panelInfo.TabIndex = 1; + this.panelInfo.Resize += new System.EventHandler(this.panelInfo_Resize); // // textBox8 // @@ -356,10 +298,10 @@ namespace WindowsFormsApp6 this.tabControl1.Controls.Add(this.tabPage3); this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; this.tabControl1.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Bold); - this.tabControl1.Location = new System.Drawing.Point(3, 203); + this.tabControl1.Location = new System.Drawing.Point(3, 123); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; - this.tabControl1.Size = new System.Drawing.Size(1194, 514); + this.tabControl1.Size = new System.Drawing.Size(1194, 594); this.tabControl1.TabIndex = 2; // // tabPage1 @@ -367,7 +309,7 @@ namespace WindowsFormsApp6 this.tabPage1.Location = new System.Drawing.Point(4, 32); this.tabPage1.Name = "tabPage1"; this.tabPage1.Padding = new System.Windows.Forms.Padding(3); - this.tabPage1.Size = new System.Drawing.Size(1186, 478); + this.tabPage1.Size = new System.Drawing.Size(1186, 558); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "⏱️ 液体吸收时间"; this.tabPage1.UseVisualStyleBackColor = true; @@ -377,7 +319,7 @@ namespace WindowsFormsApp6 this.tabPage2.Location = new System.Drawing.Point(4, 32); this.tabPage2.Name = "tabPage2"; this.tabPage2.Padding = new System.Windows.Forms.Padding(3); - this.tabPage2.Size = new System.Drawing.Size(1186, 478); + this.tabPage2.Size = new System.Drawing.Size(1186, 558); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "💧 液体吸收量"; this.tabPage2.UseVisualStyleBackColor = true; @@ -387,7 +329,7 @@ namespace WindowsFormsApp6 this.tabPage3.Location = new System.Drawing.Point(4, 32); this.tabPage3.Name = "tabPage3"; this.tabPage3.Padding = new System.Windows.Forms.Padding(3); - this.tabPage3.Size = new System.Drawing.Size(1186, 478); + this.tabPage3.Size = new System.Drawing.Size(1186, 558); this.tabPage3.TabIndex = 2; this.tabPage3.Text = "📈 液体芯吸速率"; this.tabPage3.UseVisualStyleBackColor = true; @@ -484,8 +426,6 @@ namespace WindowsFormsApp6 this.Text = "非织造布液体吸收性能测试系统"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing); this.tableLayoutPanel1.ResumeLayout(false); - this.panelTop.ResumeLayout(false); - this.panelTop.PerformLayout(); this.tableLayoutPanel2.ResumeLayout(false); this.panelTitle.ResumeLayout(false); this.panelInfo.ResumeLayout(false); @@ -498,10 +438,6 @@ namespace WindowsFormsApp6 #endregion private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; - private System.Windows.Forms.Panel panelTop; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.Button button1; - private System.Windows.Forms.ComboBox comboBox1; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; private System.Windows.Forms.Panel panelTitle; private System.Windows.Forms.Label label1; diff --git a/WindowsFormsApp6/MainForm.cs b/WindowsFormsApp6/MainForm.cs index 0030643..e0b1fed 100644 --- a/WindowsFormsApp6/MainForm.cs +++ b/WindowsFormsApp6/MainForm.cs @@ -16,22 +16,28 @@ namespace WindowsFormsApp6 private Form1 form1Instance; private Form2 form2Instance; private Form3 form3Instance; - private System.Windows.Forms.Timer clockTimer; + private System.Windows.Forms.Timer timeUpdateTimer; public MainForm() { InitializeComponent(); - InitializeClockTimer(); InitializeTabControl(); InitializeEmbeddedForms(); + InitializeTimeUpdate(); + CenterInfoControls(); } - private void InitializeClockTimer() + private void InitializeTimeUpdate() { - clockTimer = new System.Windows.Forms.Timer(); - clockTimer.Interval = 1000; - clockTimer.Tick += (s, e) => label2.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - clockTimer.Start(); + // 初始化时间显示 + textBox7.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + textBox7.ReadOnly = true; // 设置为只读 + + // 创建计时器,每秒更新一次 + timeUpdateTimer = new System.Windows.Forms.Timer(); + timeUpdateTimer.Interval = 1000; + timeUpdateTimer.Tick += (s, e) => textBox7.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + timeUpdateTimer.Start(); } private void InitializeTabControl() @@ -106,6 +112,77 @@ namespace WindowsFormsApp6 form3Instance.Show(); } + private void panelInfo_Resize(object sender, EventArgs e) + { + CenterInfoControls(); + } + + private void CenterInfoControls() + { + // 每列的宽度定义 + int col1LabelWidth = 75; // 样品名称/仪器 + int col1InputWidth = 140; + int col2LabelWidth = 75; // 物料编码/设备编号 + int col2InputWidth = 140; + int col3LabelWidth = 75; // 批号/操作人员(操作人员需要更宽) + int col3InputWidth = 140; + int col4LabelWidth = 75; // 测试时间/数据文件 + int col4InputWidth = 140; + + int gap = 15; // 列之间的间距 + + // 计算总宽度 + int totalWidth = col1LabelWidth + col1InputWidth + gap + + col2LabelWidth + col2InputWidth + gap + + col3LabelWidth + col3InputWidth + gap + + col4LabelWidth + col4InputWidth; + + int startX = (panelInfo.Width - totalWidth) / 2; + + // 第一行 Y 坐标 + int y1 = 10; + int labelOffsetY = 3; // 标签相对输入框的垂直偏移 + + // 第一列:样品名称 + int col1X = startX; + label3.Location = new Point(col1X, y1 + labelOffsetY); + textBox1.Location = new Point(col1X + col1LabelWidth, y1); + + // 第二列:物料编码 + int col2X = col1X + col1LabelWidth + col1InputWidth + gap; + label4.Location = new Point(col2X, y1 + labelOffsetY); + textBox2.Location = new Point(col2X + col2LabelWidth, y1); + + // 第三列:批号 + int col3X = col2X + col2LabelWidth + col2InputWidth + gap; + label5.Location = new Point(col3X, y1 + labelOffsetY); + textBox3.Location = new Point(col3X + col3LabelWidth, y1); + + // 第四列:测试时间 + int col4X = col3X + col3LabelWidth + col3InputWidth + gap; + label9.Location = new Point(col4X, y1 + labelOffsetY); + textBox7.Location = new Point(col4X + col4LabelWidth, y1); + + // 第二行 Y 坐标 + int y2 = 43; + + // 第一列:仪器 + label6.Location = new Point(col1X, y2 + labelOffsetY); + textBox4.Location = new Point(col1X + col1LabelWidth, y2); + + // 第二列:设备编号 + label7.Location = new Point(col2X, y2 + labelOffsetY); + textBox5.Location = new Point(col2X + col2LabelWidth, y2); + + // 第三列:操作人员 + label8.Location = new Point(col3X, y2 + labelOffsetY); + textBox6.Location = new Point(col3X + col3LabelWidth, y2); + + // 第四列:数据文件 + label10.Location = new Point(col4X, y2 + labelOffsetY); + textBox8.Location = new Point(col4X + col4LabelWidth, y2); + } + private void buttonPrint_Click(object sender, EventArgs e) { MessageBox.Show("打印功能开发中", "提示"); @@ -753,8 +830,8 @@ namespace WindowsFormsApp6 private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { - clockTimer?.Stop(); - clockTimer?.Dispose(); + timeUpdateTimer?.Stop(); + timeUpdateTimer?.Dispose(); Application.Exit(); }