This commit is contained in:
GukSang.Jin
2025-12-31 17:41:01 +08:00
parent 3ae2dd63a2
commit 894ed48b6d
3 changed files with 66 additions and 3 deletions

View File

@@ -349,8 +349,8 @@ namespace WindowsFormsApp6
clockTimer.Tick += (s, e) => label2.Text = DateTime.Now.ToString(DATE_TIME_FORMAT);
clockTimer.Start();
// 动态创建切换按钮
CreateToggleButton();
// 不再在 Form3 内部创建切换按钮,改为在 MainForm 中创建
// CreateToggleButton();
}
/// <summary>
@@ -396,7 +396,7 @@ namespace WindowsFormsApp6
/// <summary>
/// 切换表格方向(纵向/横向)
/// </summary>
private void ToggleTableLayout()
public void ToggleTableLayout()
{
isVerticalLayout = !isVerticalLayout;
@@ -416,6 +416,14 @@ namespace WindowsFormsApp6
ShowMessage($"已切换到{(isVerticalLayout ? "" : "")}布局", "布局切换", MessageBoxIcon.Information);
}
/// <summary>
/// 获取当前布局方向
/// </summary>
public bool IsVerticalLayout()
{
return isVerticalLayout;
}
/// <summary>
/// 保存当前数据
/// </summary>

View File

@@ -49,6 +49,7 @@ namespace WindowsFormsApp6
this.button5 = new System.Windows.Forms.Button();
this.buttonExport = new System.Windows.Forms.Button();
this.buttonPrint = new System.Windows.Forms.Button();
this.buttonToggleLayout = new System.Windows.Forms.Button();
this.tableLayoutPanel1.SuspendLayout();
this.panelTop.SuspendLayout();
this.tableLayoutPanel2.SuspendLayout();
@@ -348,6 +349,7 @@ namespace WindowsFormsApp6
// panelBottom
//
this.panelBottom.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(245)))), ((int)(((byte)(245)))), ((int)(((byte)(245)))));
this.panelBottom.Controls.Add(this.buttonToggleLayout);
this.panelBottom.Controls.Add(this.button5);
this.panelBottom.Controls.Add(this.buttonExport);
this.panelBottom.Controls.Add(this.buttonPrint);
@@ -358,6 +360,23 @@ namespace WindowsFormsApp6
this.panelBottom.Size = new System.Drawing.Size(1194, 74);
this.panelBottom.TabIndex = 3;
//
// buttonToggleLayout
//
this.buttonToggleLayout.Anchor = System.Windows.Forms.AnchorStyles.None;
this.buttonToggleLayout.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(52)))), ((int)(((byte)(152)))), ((int)(((byte)(219)))));
this.buttonToggleLayout.FlatAppearance.BorderSize = 0;
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.Name = "buttonToggleLayout";
this.buttonToggleLayout.Size = new System.Drawing.Size(140, 40);
this.buttonToggleLayout.TabIndex = 4;
this.buttonToggleLayout.Text = "🔄 横向布局";
this.buttonToggleLayout.UseVisualStyleBackColor = false;
this.buttonToggleLayout.Visible = false;
this.buttonToggleLayout.Click += new System.EventHandler(this.buttonToggleLayout_Click);
//
// button5
//
this.button5.Anchor = System.Windows.Forms.AnchorStyles.None;
@@ -461,5 +480,6 @@ namespace WindowsFormsApp6
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button buttonExport;
private System.Windows.Forms.Button buttonPrint;
private System.Windows.Forms.Button buttonToggleLayout;
}
}

View File

@@ -42,6 +42,16 @@ namespace WindowsFormsApp6
private void TabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
UpdateTitleForCurrentTab();
// 根据选中的 Tab 显示/隐藏切换布局按钮
// 只有在 Form3 (Tab 2, index=2) 时显示切换按钮
buttonToggleLayout.Visible = (tabControl1.SelectedIndex == 2);
// 更新切换按钮的文本
if (tabControl1.SelectedIndex == 2 && form3Instance != null)
{
UpdateToggleButtonText();
}
}
private void UpdateTitleForCurrentTab()
@@ -132,6 +142,31 @@ namespace WindowsFormsApp6
}
}
private void buttonToggleLayout_Click(object sender, EventArgs e)
{
if (form3Instance != null)
{
// 调用 Form3 的公共切换方法
form3Instance.ToggleTableLayout();
// 更新按钮文本
UpdateToggleButtonText();
}
}
/// <summary>
/// 更新切换按钮的文本
/// </summary>
private void UpdateToggleButtonText()
{
if (form3Instance != null)
{
// 使用公共方法获取布局状态
bool isVertical = form3Instance.IsVerticalLayout();
buttonToggleLayout.Text = isVertical ? "🔄 横向布局" : "🔄 纵向布局";
}
}
private void ExportIntegratedReport(string filePath)
{
try