Skip to content

Commit

Permalink
[FancyZones] Convert ARGB color values to RGB (#6277)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeraphimaZykova authored and yuyoyuppe committed Sep 2, 2020
1 parent 0292ece commit c9cb4a7
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels.Commands;
Expand Down Expand Up @@ -401,6 +402,7 @@ public string ZoneHighlightColor

set
{
value = ToRGBHex(value);
if (!value.Equals(_zoneHighlightColor))
{
_zoneHighlightColor = value;
Expand All @@ -419,6 +421,7 @@ public string ZoneBorderColor

set
{
value = ToRGBHex(value);
if (!value.Equals(_zoneBorderColor, StringComparison.OrdinalIgnoreCase))
{
_zoneBorderColor = value;
Expand All @@ -437,6 +440,7 @@ public string ZoneInActiveColor

set
{
value = ToRGBHex(value);
if (!value.Equals(_zoneInActiveColor))
{
_zoneInActiveColor = value;
Expand Down Expand Up @@ -524,5 +528,19 @@ public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
SendConfigMSG(ipcMessage.ToJsonString());
}
}

private string ToRGBHex(string color)
{
try
{
int argb = int.Parse(color.Replace("#", string.Empty), System.Globalization.NumberStyles.HexNumber);
Color clr = Color.FromArgb(argb);
return "#" + clr.R.ToString("X2") + clr.G.ToString("X2") + clr.B.ToString("X2");
}
catch (Exception)
{
return "#FFFFFF";
}
}
}
}

0 comments on commit c9cb4a7

Please sign in to comment.