[Feature] Default sizes to match Windows File Explorer (#418), version 1.3.0.8

This commit is contained in:
Markus Hofknecht 2022-07-27 21:35:09 +02:00
parent 663baa3f69
commit a14ea6fb32
12 changed files with 53 additions and 41 deletions

View file

@ -59,10 +59,17 @@ namespace SystemTrayMenu
public void Dispose()
{
taskbarForm?.Dispose();
SystemEvents.DisplaySettingsChanged -= (s, e) => SystemEvents_DisplaySettingsChanged();
menus.Dispose();
menuNotifyIcon.Dispose();
if (taskbarForm?.InvokeRequired == true)
{
Dispose();
}
else
{
taskbarForm?.Dispose();
SystemEvents.DisplaySettingsChanged -= (s, e) => SystemEvents_DisplaySettingsChanged();
menus.Dispose();
menuNotifyIcon.Dispose();
}
}
private void SystemEvents_DisplaySettingsChanged()

View file

@ -90,6 +90,7 @@ namespace SystemTrayMenu.Business
workerMainMenu.DoWork -= LoadMenu;
menus[0] = Create(menuData, Path.GetFileName(Config.Path));
menus[0].HandleCreated += (s, e) => ExecuteWatcherHistory();
Scaling.CalculateFactorByDpi(menus[0].GetDataGridView().CreateGraphics());
IconReader.MainPreload = false;
if (showMenuAfterMainPreload)
{

View file

@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.0.7")]
[assembly: AssemblyFileVersion("1.3.0.7")]
[assembly: AssemblyVersion("1.3.0.8")]
[assembly: AssemblyFileVersion("1.3.0.8")]

View file

@ -159,7 +159,7 @@ namespace SystemTrayMenu.Properties
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Configuration.SettingsProviderAttribute(typeof(CustomSettingsProvider))]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("125")]
[global::System.Configuration.DefaultSettingValueAttribute("100")]
public int SizeInPercent
{
get

View file

@ -275,7 +275,7 @@ Thanks for ideas, reporting issues and contributing!
#285 #286 [dao-net](https://github.com/dao-net),
#288 William P.,
#294 #295 #296 Stefan Mahrer,
#225 #297 #299 #317 #321 #324 #330 #386 #390 #401 #402 #407 #409 #414 #416 [chip33](https://github.com/chip33),
#225 #297 #299 #317 #321 #324 #330 #386 #390 #401 #402 #407 #409 #414 #416 #418 [chip33](https://github.com/chip33),
#298 [phanirithvij](https://github.com/phanirithvij),
#306 [wini2](https://github.com/wini2),
#370 [dna5589](https://github.com/dna5589),

View file

@ -89,7 +89,7 @@ namespace SystemTrayMenu.Helper
aboutBox.AppMoreInfo += "#235 #242 243 #247, #271 Tom, #237 Torsten S., #240 video Patrick, #244 Gunter D., #246 #329 MACE4GITHUB, #259 #310 vanjac, ";
aboutBox.AppMoreInfo += "#262 terencemcdonnell, #269 petersnows25, #272 Peter M., #273 #274 ParasiteDelta, #275 #276 #278 donaldaken, ";
aboutBox.AppMoreInfo += "#277 Jan S., #282 akuznets, #283 #284 #289 RuSieg, #285 #286 dao-net, #288 William P., #294 #295 #296 Stefan Mahrer, ";
aboutBox.AppMoreInfo += "#225 #297 #299 #317 #321 #324 #330 #386 #390 #401 #402 #407 #409 #414 #416 chip33, #298 phanirithvij, #306 wini2, #370 dna5589, #372 not-nef, #376 Michelle H. ";
aboutBox.AppMoreInfo += "#225 #297 #299 #317 #321 #324 #330 #386 #390 #401 #402 #407 #409 #414 #416 #418 chip33, #298 phanirithvij, #306 wini2, #370 dna5589, #372 not-nef, #376 Michelle H. ";
aboutBox.AppMoreInfo += "#377 SoenkeHob, #380 #394 TransLucida, #384 boydfields, #386 visusys, #387 #411 yrctw" + Environment.NewLine;
aboutBox.AppMoreInfo += @"
Sponsors - Thank you!

View file

@ -55,7 +55,7 @@ namespace SystemTrayMenu.UserInterface
ColumnIcon.DataPropertyName = "ColumnIcon";
dataGridViewCellStyle1.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle1.NullValue = "System.Drawing.Icon";
dataGridViewCellStyle1.Padding = new Padding(3, 2, 6, 2);
dataGridViewCellStyle1.Padding = new Padding(3, 1, 2, 1);
ColumnIcon.DefaultCellStyle = dataGridViewCellStyle1;
ColumnIcon.Frozen = true;
ColumnIcon.HeaderText = "ColumnIcon";

View file

@ -730,20 +730,17 @@ namespace SystemTrayMenu.UserInterface
factor = Properties.Settings.Default.RowHeighteInPercentageTouch / 100f;
}
double factorIconSizeInPercent = Properties.Settings.Default.IconSizeInPercent / 100f;
if (factor < factorIconSizeInPercent)
{
factor = factorIconSizeInPercent;
}
if (menuPredecessor == null)
{
if (dgv.Tag == null && dgv.Rows.Count > 0)
{
// Find row size based on content and apply factor
dgv.AutoResizeRows();
dgv.RowTemplate.Height = (int)(dgv.Rows[0].Height * factor);
// dgv.AutoResizeRows(); slightly incorrect depending on dpi
// 100% = 20 instead 21
// 125% = 23 instead 27, 150% = 28 instead 32
// 175% = 33 instead 37, 200% = 35 instead 42
// #418 use 21 as default and scale it manually
float rowHeightDefault = 21.24f * Scaling.FactorByDpi;
dgv.RowTemplate.Height = (int)((rowHeightDefault * factor * Scaling.Factor) + 0.5);
dgv.Tag = true;
}
}

View file

@ -1254,7 +1254,7 @@ namespace SystemTrayMenu.UserInterface
private void ButtonSizeAndLocationDefault_Click(object sender, EventArgs e)
{
numericUpDownSizeInPercent.Value = 125;
numericUpDownSizeInPercent.Value = 100;
numericUpDownIconSizeInPercent.Value = 100;
numericUpDownRowHeighteInPercentage.Value = 100;
numericUpDownMenuWidth.Value = 400;

View file

@ -20,13 +20,13 @@ namespace SystemTrayMenu.Utilities
/// <param name="dgv">datagridview.</param>
internal static void FastAutoSizeColumns(this DataGridView dgv)
{
using Graphics gfx = dgv.CreateGraphics();
gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
using Graphics graphics = dgv.CreateGraphics();
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
float widthMax = WidthMin;
DataTable data = (DataTable)dgv.DataSource;
foreach (DataRow row in data.Rows)
{
float checkWidth = gfx.MeasureString(
float checkWidth = graphics.MeasureString(
((RowData)row[2]).Text + "___",
dgv.RowTemplate.DefaultCellStyle.Font).Width;
if (checkWidth > widthMax)
@ -41,13 +41,11 @@ namespace SystemTrayMenu.Utilities
}
dgv.Columns[1].Width = (int)(widthMax + 0.5);
string stringWithWidthLikeIcon = "____";
float width0 = gfx.MeasureString(
stringWithWidthLikeIcon,
dgv.RowTemplate.DefaultCellStyle.Font).Width;
double factorIconSizeInPercent = Properties.Settings.Default.IconSizeInPercent / 100f;
dgv.Columns[0].Width = (int)(width0 * factorIconSizeInPercent);
// IcoWidth 100% = 21px, 175% is 33, +3+2 is padding from ColumnIcon
float icoWidth = (16 * Scaling.FactorByDpi) + 5;
dgv.Columns[0].Width = (int)((icoWidth * factorIconSizeInPercent * Scaling.Factor) + 0.5);
}
}
}

View file

@ -88,7 +88,13 @@ namespace SystemTrayMenu.Utilities
{
loading = false;
string extension = Path.GetExtension(path);
IconSize size = IconSize.Large;
IconSize size = IconSize.Small;
if (Scaling.Factor >= 1.25f ||
Scaling.FactorByDpi >= 1.25f ||
Properties.Settings.Default.IconSizeInPercent / 100f >= 1.25f)
{
size = IconSize.Large;
}
string key = path;
if (!string.IsNullOrEmpty(keyPath))
@ -129,8 +135,9 @@ namespace SystemTrayMenu.Utilities
loading = false;
IconSize size = IconSize.Small;
if (Scaling.Factor >= 1.50f ||
Properties.Settings.Default.IconSizeInPercent / 100f >= 1.50f)
if (Scaling.Factor >= 1.25f ||
Scaling.FactorByDpi >= 1.25f ||
Properties.Settings.Default.IconSizeInPercent / 100f >= 1.25f)
{
// IconSize.Large returns another folder icon than windows explorer
size = IconSize.Large;

View file

@ -5,25 +5,27 @@
namespace SystemTrayMenu.Utilities
{
using System;
using System.Drawing;
internal static class Scaling
{
private enum DeviceCap
{
VERTRES = 10,
DESKTOPVERTRES = 117,
}
public static float Factor { get; private set; } = 1;
internal static void Initialize()
public static float FactorByDpi { get; private set; } = 1;
public static void Initialize()
{
Factor = Properties.Settings.Default.SizeInPercent / 100f;
}
internal static int Scale(int width)
public static int Scale(int width)
{
return (int)Math.Round(width * Factor, 0, MidpointRounding.AwayFromZero);
}
public static void CalculateFactorByDpi(Graphics graphics)
{
FactorByDpi = graphics.DpiX / 96;
}
}
}