Skip to content

Commit c9cb4a7

Browse files
SeraphimaZykovayuyoyuppe
authored andcommitted
[FancyZones] Convert ARGB color values to RGB (#6277)
1 parent 0292ece commit c9cb4a7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/core/Microsoft.PowerToys.Settings.UI.Lib/ViewModels/FancyZonesViewModel.cs

+18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Drawing;
67
using System.Runtime.CompilerServices;
78
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
89
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels.Commands;
@@ -401,6 +402,7 @@ public string ZoneHighlightColor
401402

402403
set
403404
{
405+
value = ToRGBHex(value);
404406
if (!value.Equals(_zoneHighlightColor))
405407
{
406408
_zoneHighlightColor = value;
@@ -419,6 +421,7 @@ public string ZoneBorderColor
419421

420422
set
421423
{
424+
value = ToRGBHex(value);
422425
if (!value.Equals(_zoneBorderColor, StringComparison.OrdinalIgnoreCase))
423426
{
424427
_zoneBorderColor = value;
@@ -437,6 +440,7 @@ public string ZoneInActiveColor
437440

438441
set
439442
{
443+
value = ToRGBHex(value);
440444
if (!value.Equals(_zoneInActiveColor))
441445
{
442446
_zoneInActiveColor = value;
@@ -524,5 +528,19 @@ public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
524528
SendConfigMSG(ipcMessage.ToJsonString());
525529
}
526530
}
531+
532+
private string ToRGBHex(string color)
533+
{
534+
try
535+
{
536+
int argb = int.Parse(color.Replace("#", string.Empty), System.Globalization.NumberStyles.HexNumber);
537+
Color clr = Color.FromArgb(argb);
538+
return "#" + clr.R.ToString("X2") + clr.G.ToString("X2") + clr.B.ToString("X2");
539+
}
540+
catch (Exception)
541+
{
542+
return "#FFFFFF";
543+
}
544+
}
527545
}
528546
}

0 commit comments

Comments
 (0)