diff --git a/WindowsFormsApp6/Form3.cs b/WindowsFormsApp6/Form3.cs index 8cc99ba..9a23828 100644 --- a/WindowsFormsApp6/Form3.cs +++ b/WindowsFormsApp6/Form3.cs @@ -349,8 +349,8 @@ namespace WindowsFormsApp6 clockTimer.Tick += (s, e) => label2.Text = DateTime.Now.ToString(DATE_TIME_FORMAT); clockTimer.Start(); - // 动态创建切换按钮 - CreateToggleButton(); + // 不再在 Form3 内部创建切换按钮,改为在 MainForm 中创建 + // CreateToggleButton(); } /// @@ -396,7 +396,7 @@ namespace WindowsFormsApp6 /// /// 切换表格方向(纵向/横向) /// - private void ToggleTableLayout() + public void ToggleTableLayout() { isVerticalLayout = !isVerticalLayout; @@ -416,6 +416,14 @@ namespace WindowsFormsApp6 ShowMessage($"已切换到{(isVerticalLayout ? "纵向" : "横向")}布局", "布局切换", MessageBoxIcon.Information); } + /// + /// 获取当前布局方向 + /// + public bool IsVerticalLayout() + { + return isVerticalLayout; + } + /// /// 保存当前数据 /// diff --git a/WindowsFormsApp6/MainForm.Designer.cs b/WindowsFormsApp6/MainForm.Designer.cs index bab0be8..628f352 100644 --- a/WindowsFormsApp6/MainForm.Designer.cs +++ b/WindowsFormsApp6/MainForm.Designer.cs @@ -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; } } diff --git a/WindowsFormsApp6/MainForm.cs b/WindowsFormsApp6/MainForm.cs index 8625a70..4826132 100644 --- a/WindowsFormsApp6/MainForm.cs +++ b/WindowsFormsApp6/MainForm.cs @@ -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(); + } + } + + /// + /// 更新切换按钮的文本 + /// + private void UpdateToggleButtonText() + { + if (form3Instance != null) + { + // 使用公共方法获取布局状态 + bool isVertical = form3Instance.IsVerticalLayout(); + buttonToggleLayout.Text = isVertical ? "🔄 横向布局" : "🔄 纵向布局"; + } + } + private void ExportIntegratedReport(string filePath) { try