This commit is contained in:
GukSang.Jin
2026-01-03 15:59:38 +08:00
parent b42acd58b0
commit 57cea85e89
2 changed files with 97 additions and 84 deletions

View File

@@ -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();
}