GtaVUsersInfo/Sources/PanelColorSettings.cs
2024-10-10 14:52:29 +03:00

84 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GtaVUsersInfo.Sources
{
[Serializable]
public class PanelColorSettings
{
public Color leftPanel;
public Color rightPanel;
public Color centerPanel;
public Color upDownPanel;
public PanelColorSettings() { }
public PanelColorSettings(Color left, Color right, Color center, Color upDown)
{
leftPanel = left;
rightPanel = right;
centerPanel = center;
upDownPanel = upDown;
}
public static void SavePanelSettings(PanelColorSettings color)
{
string json = JsonConvert.SerializeObject(color, Formatting.Indented);
if (!Directory.Exists(Path.GetDirectoryName(Resources.paneColorlSettingsJsonPath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(Resources.paneColorlSettingsJsonPath));
}
File.WriteAllText(Resources.paneColorlSettingsJsonPath, json);
}
public static PanelColorSettings LoadPanelSettings()
{
try
{
string json = File.ReadAllText(Resources.paneColorlSettingsJsonPath);
return JsonConvert.DeserializeObject<PanelColorSettings>(json);
}
catch (FileNotFoundException)
{
Console.WriteLine($"Файл с цветами панелей не найден: {Resources.paneColorlSettingsJsonPath}");
return null;
}
catch (JsonException ex)
{
Console.WriteLine($"Ошибка при десериализации JSON с цветами панелей: {ex.Message}");
return null;
}
catch (Exception ex)
{
Console.WriteLine($"Произошла неожиданная ошибка при открытии файла с цветами панелей: {ex.Message}");
return null;
}
}
public static void ChangeFontInControls(Control parent, Color color)
{
foreach (Control control in parent.Controls)
{
if (control is TextBox ||
control is Button ||
control is ComboBox ||
control is Label)
{
control.BackColor = color;
}
if (control.HasChildren)
{
ChangeFontInControls(control, color);
}
}
}
}
}