-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainFormApp.cs
113 lines (93 loc) · 2.98 KB
/
MainFormApp.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SuggestNumbersApp
{
public partial class MainFormApp : Form
{
public MainFormApp()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
Accuracy.Visible = !IntegersOnly.Checked;
RecalculateSuggestedType();
}
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
RecalculateSuggestedType();
}
private void textBox_TextChanged(object sender, EventArgs e)
{
RecalculateSuggestedType();
ValidateMinAndMaxValue();
}
private void RecalculateSuggestedType()
{
if (isInputComplete())
{
var minValue = BigInteger.Parse(textBox1.Text);
var maxValue = BigInteger.Parse(textBox2.Text);
if (maxValue >= minValue)
{
SuggestedTypeResult.Text =
NumericTypeSuggester.GetName(
minValue,
maxValue,
IntegersOnly.Checked,
Accuracy.Checked);
return;
}
}
SuggestedTypeResult.Text = "Не хватает данных!";
}
private void ValidateMinAndMaxValue()
{
bool isValid = true;
if(isInputComplete())
{
var minValue = BigInteger.Parse(textBox1.Text);
var maxValue = BigInteger.Parse(textBox2.Text);
if (maxValue < minValue)
{
isValid = false;
}
}
textBox2.BackColor = isValid ? Color.White : Color.MediumVioletRed;
}
private bool isInputComplete()
{
return textBox1.Text.Length > 0 && textBox1.Text != "-" &&
textBox2.Text.Length > 0 && textBox2.Text != "-";
}
private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
var textBox = (TextBox)sender;
if(!IsValidInput(e.KeyChar, textBox)) {
e.Handled = true;
}
}
private bool IsValidInput(char keyChar, TextBox textBox)
{
return char.IsControl(keyChar) || char.IsDigit(keyChar) ||
(keyChar == '-' && textBox.SelectionStart == 0);
}
private void label2_Click(object sender, EventArgs e)
{
}
private void SuggestedTypeResult_Click(object sender, EventArgs e)
{
}
}
}