更新
This commit is contained in:
10
WindowsFormsApp6/MainForm.Designer.cs
generated
10
WindowsFormsApp6/MainForm.Designer.cs
generated
@@ -356,7 +356,7 @@ namespace WindowsFormsApp6
|
||||
this.buttonToggleLayout.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.buttonToggleLayout.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Bold);
|
||||
this.buttonToggleLayout.ForeColor = System.Drawing.Color.White;
|
||||
this.buttonToggleLayout.Location = new System.Drawing.Point(197, 17);
|
||||
this.buttonToggleLayout.Location = new System.Drawing.Point(447, 17);
|
||||
this.buttonToggleLayout.Name = "buttonToggleLayout";
|
||||
this.buttonToggleLayout.Size = new System.Drawing.Size(140, 40);
|
||||
this.buttonToggleLayout.TabIndex = 4;
|
||||
@@ -365,7 +365,7 @@ namespace WindowsFormsApp6
|
||||
this.buttonToggleLayout.Visible = false;
|
||||
this.buttonToggleLayout.Click += new System.EventHandler(this.ButtonToggleLayout_Click);
|
||||
//
|
||||
// button5
|
||||
// button5 (模拟数据 - 暂时隐藏)
|
||||
//
|
||||
this.button5.Anchor = System.Windows.Forms.AnchorStyles.None;
|
||||
this.button5.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(89)))), ((int)(((byte)(182)))));
|
||||
@@ -379,6 +379,7 @@ namespace WindowsFormsApp6
|
||||
this.button5.TabIndex = 3;
|
||||
this.button5.Text = "🎲 模拟数据";
|
||||
this.button5.UseVisualStyleBackColor = false;
|
||||
this.button5.Visible = false;
|
||||
this.button5.Click += new System.EventHandler(this.Button5_Click);
|
||||
//
|
||||
// buttonExport
|
||||
@@ -389,7 +390,7 @@ namespace WindowsFormsApp6
|
||||
this.buttonExport.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.buttonExport.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Bold);
|
||||
this.buttonExport.ForeColor = System.Drawing.Color.White;
|
||||
this.buttonExport.Location = new System.Drawing.Point(677, 17);
|
||||
this.buttonExport.Location = new System.Drawing.Point(607, 17);
|
||||
this.buttonExport.Name = "buttonExport";
|
||||
this.buttonExport.Size = new System.Drawing.Size(140, 40);
|
||||
this.buttonExport.TabIndex = 1;
|
||||
@@ -397,7 +398,7 @@ namespace WindowsFormsApp6
|
||||
this.buttonExport.UseVisualStyleBackColor = false;
|
||||
this.buttonExport.Click += new System.EventHandler(this.ButtonExport_Click);
|
||||
//
|
||||
// buttonPrint
|
||||
// buttonPrint (打印 - 暂时隐藏)
|
||||
//
|
||||
this.buttonPrint.Anchor = System.Windows.Forms.AnchorStyles.None;
|
||||
this.buttonPrint.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(52)))), ((int)(((byte)(152)))), ((int)(((byte)(219)))));
|
||||
@@ -411,6 +412,7 @@ namespace WindowsFormsApp6
|
||||
this.buttonPrint.TabIndex = 0;
|
||||
this.buttonPrint.Text = "🖨️ 打印";
|
||||
this.buttonPrint.UseVisualStyleBackColor = false;
|
||||
this.buttonPrint.Visible = false;
|
||||
this.buttonPrint.Click += new System.EventHandler(this.ButtonPrint_Click);
|
||||
//
|
||||
// MainForm
|
||||
|
||||
@@ -51,6 +51,10 @@ namespace WindowsFormsApp6
|
||||
InitializeTimeUpdate();
|
||||
InitializeSerialPortAndModbus();
|
||||
CenterInfoControls();
|
||||
CenterBottomButtons();
|
||||
|
||||
// 监听窗体大小变化以重新居中按钮
|
||||
this.Resize += (s, e) => CenterBottomButtons();
|
||||
}
|
||||
|
||||
private void InitializeTimeUpdate()
|
||||
@@ -1540,6 +1544,40 @@ namespace WindowsFormsApp6
|
||||
textBox8.Location = new Point(col4X + col4LabelWidth, y2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态居中底部按钮
|
||||
/// </summary>
|
||||
private void CenterBottomButtons()
|
||||
{
|
||||
// 收集所有可见的按钮
|
||||
List<Button> visibleButtons = new List<Button>();
|
||||
|
||||
if (buttonToggleLayout.Visible) visibleButtons.Add(buttonToggleLayout);
|
||||
if (button5.Visible) visibleButtons.Add(button5);
|
||||
if (buttonPrint.Visible) visibleButtons.Add(buttonPrint);
|
||||
if (buttonExport.Visible) visibleButtons.Add(buttonExport);
|
||||
|
||||
if (visibleButtons.Count == 0) return;
|
||||
|
||||
// 按钮参数
|
||||
int buttonWidth = 140;
|
||||
int buttonGap = 20; // 按钮之间的间距
|
||||
int buttonY = 17;
|
||||
|
||||
// 计算总宽度
|
||||
int totalWidth = visibleButtons.Count * buttonWidth + (visibleButtons.Count - 1) * buttonGap;
|
||||
|
||||
// 计算起始X坐标(居中)
|
||||
int startX = (panelBottom.Width - totalWidth) / 2;
|
||||
|
||||
// 依次设置每个按钮的位置
|
||||
for (int i = 0; i < visibleButtons.Count; i++)
|
||||
{
|
||||
int x = startX + i * (buttonWidth + buttonGap);
|
||||
visibleButtons[i].Location = new Point(x, buttonY);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonPrint_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show("打印功能开发中", "提示");
|
||||
|
||||
Reference in New Issue
Block a user