-
Notifications
You must be signed in to change notification settings - Fork 3
/
LineAreaStyleForm.cs
94 lines (84 loc) · 3.17 KB
/
LineAreaStyleForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace KMZRebuilder
{
public partial class LineAreaStyleForm : Form
{
public LineAreaStyleForm()
{
InitializeComponent();
DialogResult = DialogResult.Cancel;
}
private void LColor_Validating(object sender, CancelEventArgs e)
{
string hex = (sender as MaskedTextBox).Text;
e.Cancel = !Regex.IsMatch(hex, @"^(#[\dA-Fa-f]{0,6})$");
}
private void LColor_TextChanged(object sender, EventArgs e)
{
string hex = (sender as MaskedTextBox).Text;
if (Regex.IsMatch(hex, @"^(#[\dA-Fa-f]{0,6})$"))
LBColor.BackColor = RGBConverter(hex);
}
private void AColor_TextChanged(object sender, EventArgs e)
{
string hex = (sender as MaskedTextBox).Text;
if (Regex.IsMatch(hex, @"^(#[\dA-Fa-f]{0,6})$"))
ABColor.BackColor = RGBConverter(hex);
}
private void LBColor_Click(object sender, EventArgs e)
{
System.Windows.Forms.ColorDialog cd = new System.Windows.Forms.ColorDialog();
cd.FullOpen = true;
cd.Color = RGBConverter(LColor.Text);
if (cd.ShowDialog() == DialogResult.OK)
{
LColor.Text = HexConverter(Color.FromArgb(255, cd.Color));
LBColor.BackColor = Color.FromArgb(255, cd.Color);
};
cd.Dispose();
}
private void ABColor_Click(object sender, EventArgs e)
{
System.Windows.Forms.ColorDialog cd = new System.Windows.Forms.ColorDialog();
cd.FullOpen = true;
cd.Color = RGBConverter(AColor.Text);
if (cd.ShowDialog() == DialogResult.OK)
{
AColor.Text = HexConverter(Color.FromArgb(255, cd.Color));
ABColor.BackColor = Color.FromArgb(255, cd.Color);
};
cd.Dispose();
}
public static String HexConverter(Color c)
{
return "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
}
public static String HexStyleConverter(Color c)
{
return c.A.ToString("X2") + c.B.ToString("X2") + c.G.ToString("X2") + c.R.ToString("X2");
}
public static Color RGBConverter(string hex)
{
Color rtn = Color.Black;
try
{
return Color.FromArgb(
int.Parse(hex.Substring(1, 2), System.Globalization.NumberStyles.HexNumber),
int.Parse(hex.Substring(3, 2), System.Globalization.NumberStyles.HexNumber),
int.Parse(hex.Substring(5, 2), System.Globalization.NumberStyles.HexNumber));
}
catch (Exception ex)
{
//doing nothing
}
return rtn;
}
}
}