[Feature] Main Menu Loading icon and fix warning / clean code (#215), version 1.0.20.5

This commit is contained in:
Markus Hofknecht 2021-10-10 16:44:06 +02:00
parent b4f3e4e6b5
commit 30312cc025
37 changed files with 75 additions and 427 deletions

View file

@ -12,7 +12,6 @@ namespace SystemTrayMenu.Business
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security;
using System.Windows.Forms;
using SystemTrayMenu.DataClasses;
using SystemTrayMenu.Handler;

View file

@ -424,9 +424,9 @@ namespace SystemTrayMenu
str = str.Replace("#585858", htmlColorCode);
byteArray = Encoding.UTF8.GetBytes(str);
using (var stream = new MemoryStream(byteArray))
using (MemoryStream stream = new MemoryStream(byteArray))
{
var svgDocument = SvgDocument.Open<SvgDocument>(stream);
SvgDocument svgDocument = SvgDocument.Open<SvgDocument>(stream);
svgDocument.Color = new SvgColourServer(Color.Black);
return svgDocument.Draw();
}
@ -467,7 +467,7 @@ namespace SystemTrayMenu
private static void UpgradeIfNotUpgraded()
{
var path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming).FilePath;
string path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming).FilePath;
path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
if (!Settings.Default.IsUpgraded)
{

View file

@ -6,13 +6,10 @@ namespace SystemTrayMenu.DataClasses
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security;
using System.Text;
using System.Windows.Forms;
using IWshRuntimeLibrary;
@ -292,18 +289,6 @@ namespace SystemTrayMenu.DataClasses
bool handled = false;
resolvedLnkPath = FileLnk.GetResolvedFileName(TargetFilePath);
#if false // FileLnk.IsDirectory was very slow if it was a network path, PingHost was still slow if not exists therefore we used IsNetworkPath
if (FileLnk.IsNetworkPath(resolvedLnkPath))
{
string nameOrAdress = resolvedLnkPath.Split(@"\\")[1].Split(@"\").First();
if (!FileLnk.PingHost(nameOrAdress))
{
return handled;
}
}
if (FileLnk.IsDirectory(resolvedLnkPath))
#endif
if (string.IsNullOrEmpty(Path.GetExtension(resolvedLnkPath)))
{
icon = IconReader.GetFolderIconSTA(TargetFilePath, IconReader.FolderType.Open, true);
@ -318,7 +303,6 @@ namespace SystemTrayMenu.DataClasses
{
Log.Info($"Resolve *.LNK '{TargetFilePath}' has no icon");
}
#if false //icons were incorrect, performance increase when removing
else
{
IWshShell shell = new WshShell();
@ -326,27 +310,8 @@ namespace SystemTrayMenu.DataClasses
as IWshShortcut;
arguments = lnk.Arguments;
workingDirectory = lnk.WorkingDirectory;
string iconLocation = lnk.IconLocation;
if (iconLocation.Length > 2)
{
iconLocation = iconLocation[0..^2];
if (System.IO.File.Exists(iconLocation))
{
try
{
icon = Icon.ExtractAssociatedIcon(iconLocation);
handled = true;
}
catch (ArgumentException ex)
{
Log.Warn($"iconLocation:'{iconLocation}'", ex);
}
}
}
TargetFilePath = resolvedLnkPath;
}
#endif
SetText(Path.GetFileNameWithoutExtension(TargetFilePathOrig));

View file

@ -55,7 +55,7 @@ namespace SystemTrayMenu.Helpers
private static void CreateShortcut(string url, string pathToStoreFile)
{
string pathToStoreIcons = Path.Combine(pathToStoreFile, "ico");
var client = new WebClient();
WebClient client = new WebClient();
if (!Directory.Exists(pathToStoreIcons))
{
Directory.CreateDirectory(pathToStoreIcons);
@ -72,7 +72,7 @@ namespace SystemTrayMenu.Helpers
ImagingHelper.ConvertToIcon(pathIconPng, pathIcon, 32);
File.Delete(pathIconPng);
var title = url;
string title = url;
title = title.Replace("/", " ").
Replace("https", string.Empty).

View file

@ -5,6 +5,7 @@
namespace SystemTrayMenu.Helpers
{
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
@ -81,7 +82,7 @@ namespace SystemTrayMenu.Helpers
iconWriter.Write((int)memoryStream.Length);
// 12-15 offset of image data
iconWriter.Write((int)(6 + 16));
iconWriter.Write(6 + 16);
// write image data
// png data must contain the whole png data file
@ -116,5 +117,35 @@ namespace SystemTrayMenu.Helpers
return ConvertToIcon(inputStream, outputStream, size, preserveAspectRatio);
}
}
public static Image RotateImage(Image img, float rotationAngle)
{
// create an empty Bitmap image
Bitmap bmp = new Bitmap(img.Width, img.Height);
// turn the Bitmap into a Graphics object
Graphics gfx = Graphics.FromImage(bmp);
// now we set the rotation point to the center of our image
gfx.TranslateTransform(0.5f + ((float)bmp.Width / 2), 0.5f + ((float)bmp.Height / 2));
// now rotate the image
gfx.RotateTransform(rotationAngle);
gfx.TranslateTransform(0.5f - ((float)bmp.Width / 2), 0.5f - ((float)bmp.Height / 2));
// set the InterpolationMode to HighQualityBicubic so to ensure a high
// quality image once it is transformed to the specified size
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
// now draw our new image onto the graphics object
gfx.DrawImage(img, new Point(0, 0));
// dispose of our Graphics object
gfx.Dispose();
// return the image
return bmp;
}
}
}

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.0.20.4")]
[assembly: AssemblyFileVersion("1.0.20.4")]
[assembly: AssemblyVersion("1.0.20.5")]
[assembly: AssemblyFileVersion("1.0.20.5")]

View file

@ -120,186 +120,6 @@ namespace SystemTrayMenu.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L010 {
get {
object obj = ResourceManager.GetObject("L010", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L020 {
get {
object obj = ResourceManager.GetObject("L020", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L030 {
get {
object obj = ResourceManager.GetObject("L030", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L040 {
get {
object obj = ResourceManager.GetObject("L040", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L050 {
get {
object obj = ResourceManager.GetObject("L050", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L060 {
get {
object obj = ResourceManager.GetObject("L060", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L070 {
get {
object obj = ResourceManager.GetObject("L070", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L080 {
get {
object obj = ResourceManager.GetObject("L080", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L090 {
get {
object obj = ResourceManager.GetObject("L090", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L100 {
get {
object obj = ResourceManager.GetObject("L100", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L110 {
get {
object obj = ResourceManager.GetObject("L110", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L120 {
get {
object obj = ResourceManager.GetObject("L120", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L130 {
get {
object obj = ResourceManager.GetObject("L130", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L140 {
get {
object obj = ResourceManager.GetObject("L140", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L150 {
get {
object obj = ResourceManager.GetObject("L150", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L160 {
get {
object obj = ResourceManager.GetObject("L160", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L170 {
get {
object obj = ResourceManager.GetObject("L170", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon L180 {
get {
object obj = ResourceManager.GetObject("L180", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>

View file

@ -118,66 +118,12 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="L080" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L080.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L020" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L020.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L070" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L070.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L140" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L140.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L160" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L160.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L100" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L100.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L060" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L060.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L180" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L180.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="White50Percentage" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\White50Percentage.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L150" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L150.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L120" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L120.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L170" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L170.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="SystemTrayMenu" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\SystemTrayMenu.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L090" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L090.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L040" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L040.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L010" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L010.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L030" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L030.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L050" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L050.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L130" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L130.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="L110" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LoadingIcon\L110.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="search" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\search.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

View file

@ -10,7 +10,6 @@ namespace SystemTrayMenu.UserInterface
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Security;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Microsoft.Win32;

View file

@ -5,39 +5,27 @@
namespace SystemTrayMenu.UserInterface
{
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using SystemTrayMenu.Helper;
using SystemTrayMenu.Helpers;
using SystemTrayMenu.Utilities;
using R = SystemTrayMenu.Properties.Resources;
using Timer = System.Windows.Forms.Timer;
internal class AppNotifyIcon : IDisposable
{
private const int Interval60FPS = 16; // 60fps=>1s/60fps=~16.6ms
private static Icon systemTrayMenu = R.SystemTrayMenu;
private static readonly Icon LoadingIcon = Properties.Resources.Loading;
private static Icon systemTrayMenu = Properties.Resources.SystemTrayMenu;
private readonly Timer load = new Timer();
private readonly NotifyIcon notifyIcon = new NotifyIcon();
private readonly int indexLoad;
private readonly List<Icon> bitmapsLoading = new List<Icon>()
{
R.L010, R.L020, R.L030,
R.L040, R.L050, R.L060, R.L070, R.L080, R.L090, R.L100, R.L110, R.L120,
R.L130, R.L140, R.L150, R.L160, R.L170, R.L180,
};
private DateTime timeLoadingStart;
private bool threadsLoading;
private int loadCount;
private int rotationAngle;
public AppNotifyIcon()
{
indexLoad = bitmapsLoading.Count;
notifyIcon.Icon = bitmapsLoading.First();
notifyIcon.Icon = LoadingIcon;
load.Tick += Load_Tick;
load.Interval = Interval60FPS;
load.Interval = 15;
notifyIcon.Text = Translator.GetText("SystemTrayMenu");
notifyIcon.Visible = true;
@ -101,7 +89,6 @@ namespace SystemTrayMenu.UserInterface
public void LoadingStart()
{
timeLoadingStart = DateTime.Now;
threadsLoading = true;
load.Start();
}
@ -124,16 +111,27 @@ namespace SystemTrayMenu.UserInterface
{
if (threadsLoading)
{
if (DateTime.Now - timeLoadingStart > new TimeSpan(0, 0, 0, 0, 500))
rotationAngle = rotationAngle + 5;
using (Bitmap bitmapLoading = new Bitmap(ImagingHelper.RotateImage(LoadingIcon.ToBitmap(), rotationAngle)))
{
notifyIcon.Icon = bitmapsLoading[loadCount++ % indexLoad];
DisposeIconIfNotDefaultIcon();
notifyIcon.Icon = Icon.FromHandle(bitmapLoading.GetHicon());
}
}
else
{
DisposeIconIfNotDefaultIcon();
notifyIcon.Icon = systemTrayMenu;
load.Stop();
}
void DisposeIconIfNotDefaultIcon()
{
if (notifyIcon.Icon.GetHashCode() != systemTrayMenu.GetHashCode())
{
notifyIcon.Icon?.Dispose();
}
}
}
}
}

View file

@ -6,10 +6,8 @@ namespace SystemTrayMenu.UserInterface
{
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;
[Designer(typeof(ScrollbarControlDesigner))]
public class CustomScrollbar : UserControl
@ -56,10 +54,7 @@ namespace SystemTrayMenu.UserInterface
[Description("LargeChange")]
public float LargeChange
{
get
{
return largeChange;
}
get => largeChange;
set
{
@ -75,10 +70,7 @@ namespace SystemTrayMenu.UserInterface
[Description("SmallChange")]
public float SmallChange
{
get
{
return smallChange;
}
get => smallChange;
set
{
@ -94,10 +86,7 @@ namespace SystemTrayMenu.UserInterface
[Description("Minimum")]
public int Minimum
{
get
{
return minimum;
}
get => minimum;
set
{
@ -113,10 +102,7 @@ namespace SystemTrayMenu.UserInterface
[Description("Maximum")]
public int Maximum
{
get
{
return maximum;
}
get => maximum;
set
{
@ -132,10 +118,7 @@ namespace SystemTrayMenu.UserInterface
[Description("Value")]
public int Value
{
get
{
return value;
}
get => value;
set
{
@ -156,25 +139,13 @@ namespace SystemTrayMenu.UserInterface
}
}
public int Delta
{
get
{
return Value - lastValue;
}
}
public int Delta => Value - lastValue;
public override bool AutoSize
{
get
{
return base.AutoSize;
}
get => base.AutoSize;
set
{
base.AutoSize = value;
}
set => base.AutoSize = value;
}
public void CustomScrollbar_MouseWheel(object sender, MouseEventArgs e)

View file

@ -4,11 +4,7 @@
namespace SystemTrayMenu.UserInterface
{
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;
internal class ScrollbarControlDesigner : ControlDesigner

View file

@ -4,7 +4,6 @@
namespace SystemTrayMenu.UserInterface
{
using System;
using System.Drawing;
using System.Windows.Forms;
using SystemTrayMenu.Utilities;
@ -38,7 +37,7 @@ namespace SystemTrayMenu.UserInterface
labelTitle.AutoEllipsis = true;
labelTitle.AutoSize = true;
labelTitle.Dock = DockStyle.Fill;
labelTitle.Font = new Font("Segoe UI", 8.25F * Scaling.Factor, FontStyle.Bold, GraphicsUnit.Point, (byte)0);
labelTitle.Font = new Font("Segoe UI", 8.25F * Scaling.Factor, FontStyle.Bold, GraphicsUnit.Point, 0);
labelTitle.ForeColor = Color.Black;
labelTitle.Location = new Point(0, 0);
labelTitle.Margin = new Padding(0);
@ -83,10 +82,10 @@ namespace SystemTrayMenu.UserInterface
ColumnText,
});
dataGridViewCellStyle3.Font = new Font("Segoe UI", 7F * Scaling.Factor, FontStyle.Regular, GraphicsUnit.Pixel, (byte)0);
dataGridViewCellStyle3.Font = new Font("Segoe UI", 7F * Scaling.Factor, FontStyle.Regular, GraphicsUnit.Pixel, 0);
dgv.RowsDefaultCellStyle = dataGridViewCellStyle3;
dgv.RowTemplate.DefaultCellStyle.Font = new Font("Segoe UI", 9F * Scaling.Factor, FontStyle.Regular, GraphicsUnit.Point, (byte)0);
dgv.RowTemplate.DefaultCellStyle.Font = new Font("Segoe UI", 9F * Scaling.Factor, FontStyle.Regular, GraphicsUnit.Point, 0);
dgv.RowTemplate.Height = 20;
dgv.RowTemplate.ReadOnly = true;
@ -119,8 +118,8 @@ namespace SystemTrayMenu.UserInterface
Scaling.Scale(pictureBoxFilesCount.Width),
Scaling.Scale(pictureBoxFilesCount.Height));
labelFoldersCount.Font = new Font("Segoe UI", 7F * Scaling.Factor, FontStyle.Bold, GraphicsUnit.Point, (byte)0);
labelFilesCount.Font = new Font("Segoe UI", 7F * Scaling.Factor, FontStyle.Bold, GraphicsUnit.Point, (byte)0);
labelFoldersCount.Font = new Font("Segoe UI", 7F * Scaling.Factor, FontStyle.Bold, GraphicsUnit.Point, 0);
labelFilesCount.Font = new Font("Segoe UI", 7F * Scaling.Factor, FontStyle.Bold, GraphicsUnit.Point, 0);
// tableLayoutPanelDgvAndScrollbar.ResumeLayout(false);
// ((System.ComponentModel.ISupportInitialize)dgv).EndInit();

View file

@ -7,12 +7,9 @@ namespace SystemTrayMenu.UserInterface
using System;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Svg;
using SystemTrayMenu.DataClasses;
using SystemTrayMenu.DllImports;
using SystemTrayMenu.Helpers;
@ -794,40 +791,10 @@ namespace SystemTrayMenu.UserInterface
PictureBox pictureBox = (PictureBox)sender;
rotationAngle = rotationAngle + 5;
e.Graphics.DrawImage(
RotateImage(LoadingIcon.ToBitmap(), rotationAngle),
ImagingHelper.RotateImage(LoadingIcon.ToBitmap(), rotationAngle),
new Rectangle(Point.Empty, new Size(pictureBox.ClientSize.Width - 2, pictureBox.ClientSize.Height - 2)));
}
private Image RotateImage(Image img, float rotationAngle)
{
// create an empty Bitmap image
Bitmap bmp = new Bitmap(img.Width, img.Height);
// turn the Bitmap into a Graphics object
Graphics gfx = Graphics.FromImage(bmp);
// now we set the rotation point to the center of our image
gfx.TranslateTransform(0.5f + ((float)bmp.Width / 2), 0.5f + ((float)bmp.Height / 2));
// now rotate the image
gfx.RotateTransform(rotationAngle);
gfx.TranslateTransform(0.5f - ((float)bmp.Width / 2), 0.5f - ((float)bmp.Height / 2));
// set the InterpolationMode to HighQualityBicubic so to ensure a high
// quality image once it is transformed to the specified size
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
// now draw our new image onto the graphics object
gfx.DrawImage(img, new Point(0, 0));
// dispose of our Graphics object
gfx.Dispose();
// return the image
return bmp;
}
private void PictureBoxMenuOpenFolder_Paint(object sender, PaintEventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;

View file

@ -6,7 +6,6 @@ namespace SystemTrayMenu.UserInterface
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Reflection;
@ -24,8 +23,8 @@ namespace SystemTrayMenu.UserInterface
private static readonly Icon SystemTrayMenu = Resources.SystemTrayMenu;
private readonly string newHotKey = string.Empty;
private readonly ColorConverter colorConverter = new ColorConverter();
private bool inHotkey;
private ColorConverter colorConverter = new ColorConverter();
public SettingsForm()
{

View file

@ -7,7 +7,6 @@ namespace SystemTrayMenu.Utilities
using System;
using System.IO;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Threading;
using Shell32;
@ -36,29 +35,6 @@ namespace SystemTrayMenu.Utilities
return resolvedFilename;
}
#if false // FileLnk.IsDirectory was very slow if it was a network path, PingHost was still slow if not exists therefore we used IsNetworkPath
public static bool IsDirectory(string filePath)
{
bool isDirectory = false;
if (Directory.Exists(filePath))
{
FileAttributes attributes = File.GetAttributes(filePath);
if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
{
isDirectory = true;
}
}
return isDirectory;
}
public static bool IsNetworkPath(string path)
{
return path.StartsWith(@"\\", StringComparison.InvariantCulture) &&
!path.StartsWith(@"\\?\", StringComparison.InvariantCulture);
}
#endif
public static bool IsNetworkRoot(string path)
{
return path.StartsWith(@"\\", StringComparison.InvariantCulture) &&

View file

@ -49,7 +49,7 @@ namespace SystemTrayMenu.Utilities
}
}
internal static bool ClearIfCacheTooBig()
public static bool ClearIfCacheTooBig()
{
bool cleared = false;
if (DictIconCache.Count > 200)
@ -64,7 +64,6 @@ namespace SystemTrayMenu.Utilities
public static Icon GetFileIconWithCache(string filePath, bool linkOverlay, bool updateIconInBackground, out bool loading)
{
Icon icon = null;
loading = false;
string extension = Path.GetExtension(filePath);
IconSize size = IconSize.Small;
@ -79,7 +78,7 @@ namespace SystemTrayMenu.Utilities
key = extension + linkOverlay;
}
if (!DictIconCache.TryGetValue(key, out icon))
if (!DictIconCache.TryGetValue(key, out Icon icon))
{
icon = LoadingIcon;
loading = true;

View file

@ -6,7 +6,6 @@ namespace SystemTrayMenu.Utilities
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;

View file

@ -5,7 +5,6 @@
namespace SystemTrayMenu.Utilities
{
using System;
using System.Drawing;
internal static class Scaling
{
@ -26,20 +25,5 @@ namespace SystemTrayMenu.Utilities
{
return (int)Math.Round(width * Factor, 0, MidpointRounding.AwayFromZero);
}
/// <summary>
/// https://stackoverflow.com/questions/5977445/how-to-get-windows-display-settings
/// Since .net core 3.1 not more necessary / always returns 1.
/// </summary>
private static void CalculateScalingFactor()
{
Graphics g = Graphics.FromHwnd(IntPtr.Zero);
IntPtr desktop = g.GetHdc();
int logicalScreenHeight = DllImports.NativeMethods.Gdi32GetDeviceCaps(
desktop, (int)DeviceCap.VERTRES);
int physicalScreenHeight = DllImports.NativeMethods.Gdi32GetDeviceCaps(
desktop, (int)DeviceCap.DESKTOPVERTRES);
Factor = physicalScreenHeight / (float)logicalScreenHeight;
}
}
}