From 7280aebbd87a48666eb5cac8edcd3b2d1bf27481 Mon Sep 17 00:00:00 2001 From: WMJ Date: Mon, 25 Aug 2025 20:35:29 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BC=81=E6=94=B9=E5=96=84=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E7=9A=84=E9=AB=98=E5=88=86=E8=BE=A8=E7=8E=87=E5=B1=8F=E5=B9=95?= =?UTF-8?q?=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Common/FormHelper.cs | 18 ++++-- .../AutoBookmark/EditAdjustmentForm.cs | 2 +- App/Functions/AutoBookmarkControl.cs | 2 +- App/Functions/DocumentInspectorControl.cs | 2 +- App/Functions/Editor/AutoBookmarkForm.cs | 2 +- App/Functions/EditorControl.cs | 15 +++-- App/Functions/InfoExchangerControl.cs | 2 +- App/Functions/MergerControl.cs | 11 ++-- App/Functions/PatcherControl.Designer.cs | 7 ++- App/Functions/PatcherControl.cs | 13 +++-- App/Functions/PatcherOptionForm.Designer.cs | 57 ++++++++++--------- App/Functions/RenameControl.cs | 13 ++--- App/MainForm.cs | 4 +- 13 files changed, 80 insertions(+), 68 deletions(-) diff --git a/App/Common/FormHelper.cs b/App/Common/FormHelper.cs index 0fb3004..97a1aa8 100644 --- a/App/Common/FormHelper.cs +++ b/App/Common/FormHelper.cs @@ -155,16 +155,26 @@ namespace PDFPatcher.Common } } - public static ToolStrip ScaleIcons(this ToolStrip toolStrip, int size) { - size = (int)(toolStrip.GetDpiScale() * size); - return toolStrip.ScaleIcons(new Size(size, size)); + public static ToolStrip ScaleElements(this ToolStrip toolStrip, float scale = 0) { + if (scale <= 0) { + scale = toolStrip.GetDpiScale(); + } + var iconSize = (int)(scale * 16); + var splitButtonWidth = (int)(11 * scale); + return toolStrip.DpiAwareScale(new Size(iconSize, iconSize), splitButtonWidth); } - public static ToolStrip ScaleIcons(this ToolStrip toolStrip, Size size) { + + public static ToolStrip DpiAwareScale(this ToolStrip toolStrip, Size size, int splitButtonWidth) { toolStrip.SuspendLayout(); toolStrip.AutoSize = false; toolStrip.ImageScalingSize = size; toolStrip.ResumeLayout(); toolStrip.AutoSize = true; + foreach (var item in toolStrip.Items) { + if (item is ToolStripSplitButton sb) { + sb.DropDownButtonWidth = splitButtonWidth; + } + } return toolStrip; } diff --git a/App/Functions/AutoBookmark/EditAdjustmentForm.cs b/App/Functions/AutoBookmark/EditAdjustmentForm.cs index 3f9ab59..ce239d2 100644 --- a/App/Functions/AutoBookmark/EditAdjustmentForm.cs +++ b/App/Functions/AutoBookmark/EditAdjustmentForm.cs @@ -46,7 +46,7 @@ namespace PDFPatcher.Functions } void OnLoad() { - _MainToolbar.ScaleIcons(16); + _MainToolbar.ScaleElements(); _FilterBox.ScaleColumnWidths(); } diff --git a/App/Functions/AutoBookmarkControl.cs b/App/Functions/AutoBookmarkControl.cs index 4df6929..f811cc7 100644 --- a/App/Functions/AutoBookmarkControl.cs +++ b/App/Functions/AutoBookmarkControl.cs @@ -27,7 +27,7 @@ namespace PDFPatcher.Functions public string DocumentPath => _SourceFileControl.Text; void OnLoad() { - _FilterToolbar.ScaleIcons(16); + _FilterToolbar.ScaleElements(); _LevelAdjustmentBox.ScaleColumnWidths(); AppContext.MainForm.SetTooltip(_SourceFileControl.FileList, "需要识别标题为书签的 PDF 源文件路径"); AppContext.MainForm.SetTooltip(_BookmarkControl.FileList, "指定识别书签后生成的信息文件或简易文本书签文件路径"); diff --git a/App/Functions/DocumentInspectorControl.cs b/App/Functions/DocumentInspectorControl.cs index 794858b..1a0dc0e 100644 --- a/App/Functions/DocumentInspectorControl.cs +++ b/App/Functions/DocumentInspectorControl.cs @@ -57,7 +57,7 @@ namespace PDFPatcher.Functions } void OnLoad() { - _MainToolbar.ScaleIcons(16); + _MainToolbar.ScaleElements(); _ObjectDetailBox.ScaleColumnWidths(); _ObjectDetailBox.EmptyListMsg = "请使用“打开”按钮加载需要检查结构的 PDF 文件,或从资源管理器拖放文件到本列表框"; diff --git a/App/Functions/Editor/AutoBookmarkForm.cs b/App/Functions/Editor/AutoBookmarkForm.cs index a92631e..7e4198a 100644 --- a/App/Functions/Editor/AutoBookmarkForm.cs +++ b/App/Functions/Editor/AutoBookmarkForm.cs @@ -26,7 +26,7 @@ namespace PDFPatcher.Functions void OnLoad() { MinimumSize = Size; - _Toolbar.ScaleIcons(16); + _Toolbar.ScaleElements(); _ConditionColumn.AsTyped(c => c.AspectGetter = o => $"字体为{o.FontName} 尺寸为{o.FontSize}{o.MatchPattern?.ToString() ?? String.Empty}"); _LevelColumn.CellEditUseWholeCell = true; diff --git a/App/Functions/EditorControl.cs b/App/Functions/EditorControl.cs index d389ec6..9285897 100644 --- a/App/Functions/EditorControl.cs +++ b/App/Functions/EditorControl.cs @@ -48,14 +48,13 @@ namespace PDFPatcher.Functions ListRecentFiles = _OpenButton_DropDownOpening; RecentFileItemClicked = _OpenButton_DropDownItemClicked; var s = this.GetDpiScale(); - var size = new Size((int)(s * 16), (int)(s * 16)); - _BookmarkToolbar.ScaleIcons(size); - _ViewerToolbar.ScaleIcons(size); - _EditMenu.ScaleIcons(size); - _RecentFileMenu.ScaleIcons(size); - _SelectionMenu.ScaleIcons(size); - _UndoMenu.ScaleIcons(size); - _ViewerMenu.ScaleIcons(size); + _BookmarkToolbar.ScaleElements(s); + _ViewerToolbar.ScaleElements(s); + _EditMenu.ScaleElements(s); + _RecentFileMenu.ScaleElements(s); + _SelectionMenu.ScaleElements(s); + _UndoMenu.ScaleElements(s); + _ViewerMenu.ScaleElements(s); _BookmarkBox.ScaleColumnWidths(s); _ViewerToolbar.Left = _BookmarkToolbar.Right; _MainPanel.SplitterDistance = (int)(_MainPanel.SplitterDistance * FormHelper.GetDpiScale(this)); diff --git a/App/Functions/InfoExchangerControl.cs b/App/Functions/InfoExchangerControl.cs index c013062..1e5afff 100644 --- a/App/Functions/InfoExchangerControl.cs +++ b/App/Functions/InfoExchangerControl.cs @@ -26,7 +26,7 @@ namespace PDFPatcher.Functions } void OnLoad() { - _MainToolbar.ScaleIcons(16); + _MainToolbar.ScaleElements(); _ItemList.ListViewItemSorter = new ListViewItemComparer(0); AppContext.MainForm.SetTooltip(_BookmarkControl.FileList, "需要导出或导入的信息文件路径"); diff --git a/App/Functions/MergerControl.cs b/App/Functions/MergerControl.cs index cb67ba6..5c4f497 100644 --- a/App/Functions/MergerControl.cs +++ b/App/Functions/MergerControl.cs @@ -30,11 +30,12 @@ namespace PDFPatcher.Functions } void OnLoad() { - _MainToolbar.ScaleIcons(16); - _FileMenu.ScaleIcons(16); - _ItemListMenu.ScaleIcons(16); - _RecentFileMenu.ScaleIcons(16); - _RecentFolderMenu.ScaleIcons(16); + var s = this.GetDpiScale(); + _MainToolbar.ScaleElements(s); + _FileMenu.ScaleElements(s); + _ItemListMenu.ScaleElements(s); + _RecentFileMenu.ScaleElements(s); + _RecentFolderMenu.ScaleElements(s); _ItemList.ScaleColumnWidths(); _BookmarkColorButton.SelectedColorChanged += (s, e) => RefreshBookmarkColor(); diff --git a/App/Functions/PatcherControl.Designer.cs b/App/Functions/PatcherControl.Designer.cs index 053ee3a..3766e78 100644 --- a/App/Functions/PatcherControl.Designer.cs +++ b/App/Functions/PatcherControl.Designer.cs @@ -167,7 +167,8 @@ // _RefreshInfoMenu // this._RefreshInfoMenu.Name = "_RefreshInfoMenu"; - this._RefreshInfoMenu.Size = new System.Drawing.Size(181, 26); + this._RefreshInfoMenu.OwnerItem = _RefreshInfo; + this._RefreshInfoMenu.Size = new System.Drawing.Size(61, 4); // // _MainToolbar // @@ -217,6 +218,7 @@ _InvertSelection, _SelectNone}); this._SelectionMenu.Name = "_SelectionMenu"; + this._SelectionMenu.OwnerItem = this._SelectionMenuItem; this._SelectionMenu.Size = new System.Drawing.Size(125, 70); this._SelectionMenu.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this._MainToolbar_ItemClicked); // @@ -417,7 +419,7 @@ this._ConfigButton.Image = global::PDFPatcher.Properties.Resources.PdfOptions; this._ConfigButton.Location = new System.Drawing.Point(253, 297); this._ConfigButton.Name = "_ConfigButton"; - this._ConfigButton.Size = new System.Drawing.Size(181, 23); + this._ConfigButton.Size = new System.Drawing.Size(181, 29); this._ConfigButton.TabIndex = 11; this._ConfigButton.Text = "设置 P&DF 文件的修改方式"; this._ConfigButton.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; @@ -454,7 +456,6 @@ this.Controls.Add(this._TargetPdfFile); this.Controls.Add(this._ItemActionsContainerBox); this.Controls.Add(this._AutoClearListBox); - this.Font = new System.Drawing.Font("SimSun", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.Name = "PatcherControl"; this.Size = new System.Drawing.Size(575, 342); this._SortMenu.ResumeLayout(false); diff --git a/App/Functions/PatcherControl.cs b/App/Functions/PatcherControl.cs index 7952124..9e0c00f 100644 --- a/App/Functions/PatcherControl.cs +++ b/App/Functions/PatcherControl.cs @@ -28,12 +28,13 @@ namespace PDFPatcher.Functions } void OnLoad() { - _MainToolbar.ScaleIcons(16); - _ItemListMenu.ScaleIcons(16); - _RecentFileMenu.ScaleIcons(16); - _RefreshInfoMenu.ScaleIcons(16); - _SelectionMenu.ScaleIcons(16); - _SortMenu.ScaleIcons(16); + var s = this.GetDpiScale(); + _MainToolbar.ScaleElements(s); + _ItemListMenu.ScaleElements(s); + _RecentFileMenu.ScaleElements(s); + _RefreshInfoMenu.ScaleElements(s); + _SelectionMenu.ScaleElements(s); + _SortMenu.ScaleElements(s); AppContext.MainForm.SetTooltip(_ConfigButton, "点击此处设置 PDF 文件的修改方式选项"); AppContext.MainForm.SetTooltip(_ActionsBox, "双击项目编辑操作选项;右键点击项目弹出上下文菜单"); diff --git a/App/Functions/PatcherOptionForm.Designer.cs b/App/Functions/PatcherOptionForm.Designer.cs index 8bc8f2c..738e89d 100644 --- a/App/Functions/PatcherOptionForm.Designer.cs +++ b/App/Functions/PatcherOptionForm.Designer.cs @@ -25,36 +25,37 @@ /// 使用代码编辑器修改此方法的内容。 /// private void InitializeComponent () { - this._OptionsBox = new PDFPatcher.Functions.PatcherOptionsControl(); - this.SuspendLayout(); - // - // _OptionsBox - // - this._OptionsBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this._OptionsBox = new PDFPatcher.Functions.PatcherOptionsControl(); + this.SuspendLayout(); + // + // _OptionsBox + // + this._OptionsBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this._OptionsBox.ForEditor = false; - this._OptionsBox.Location = new System.Drawing.Point(12, 15); - this._OptionsBox.Name = "_OptionsBox"; - this._OptionsBox.Options = null; - this._OptionsBox.Size = new System.Drawing.Size(452, 321); - this._OptionsBox.TabIndex = 0; - // - // PatcherOptionForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(476, 348); - this.Controls.Add(this._OptionsBox); - this.Font = new System.Drawing.Font("SimSun", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.MinimumSize = new System.Drawing.Size(482, 374); - this.Name = "PatcherOptionForm"; - this.ShowInTaskbar = false; - this.Text = "PDF 文档选项"; - this.ResumeLayout(false); + this._OptionsBox.ForEditor = false; + this._OptionsBox.Location = new System.Drawing.Point(18, 22); + this._OptionsBox.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this._OptionsBox.Name = "_OptionsBox"; + this._OptionsBox.Options = null; + this._OptionsBox.Size = new System.Drawing.Size(678, 482); + this._OptionsBox.TabIndex = 0; + // + // PatcherOptionForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(714, 522); + this.Controls.Add(this._OptionsBox); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(712, 533); + this.Name = "PatcherOptionForm"; + this.ShowInTaskbar = false; + this.Text = "PDF 文档选项"; + this.ResumeLayout(false); } diff --git a/App/Functions/RenameControl.cs b/App/Functions/RenameControl.cs index 8b2c69f..4932dce 100644 --- a/App/Functions/RenameControl.cs +++ b/App/Functions/RenameControl.cs @@ -26,13 +26,12 @@ namespace PDFPatcher.Functions } void OnLoad() { - var s = (int)(this.GetDpiScale() * 16); - var size = new System.Drawing.Size(s, s); - _MainToolbar.ScaleIcons(size); - _SortMenu.ScaleIcons(size); - _ItemListMenu.ScaleIcons(size); - _RecentFileMenu.ScaleIcons(size); - _RefreshInfoMenu.ScaleIcons(size); + var s = this.GetDpiScale(); + _MainToolbar.ScaleElements(s); + _SortMenu.ScaleElements(s); + _ItemListMenu.ScaleElements(s); + _RecentFileMenu.ScaleElements(s); + _RefreshInfoMenu.ScaleElements(s); _ItemList.ListViewItemSorter = new ListViewItemComparer(0); diff --git a/App/MainForm.cs b/App/MainForm.cs index 482df1a..7f717ed 100644 --- a/App/MainForm.cs +++ b/App/MainForm.cs @@ -224,7 +224,7 @@ namespace PDFPatcher // ignore loading exception firstLoad = true; } - _MainMenu.ScaleIcons(16); + _MainMenu.ScaleElements(); Text = Constants.AppName + " [" + Application.ProductVersion + "]"; MinimumSize = Size; AllowDrop = true; @@ -423,7 +423,7 @@ namespace PDFPatcher } void ScaleToolbar() { - _GeneralToolbar.ScaleIcons(16); + _GeneralToolbar.ScaleElements(); } Control GetActiveFunctionControl() {