Чтобы проверить значения TextBox
, вам просто нужно проанализировать данные / текст каждого файла как int
, просто выполнить анализ и достаточно метода проверки.
Как указывал @Jimi, для WinForms
:
private void button1_Click_1(object sender, EventArgs e)
{
int f = 0, t = 0;
if (Int32.TryParse(textBox1.Text, out f))
{
// successfully parsed
}
if (Int32.TryParse(textBox3.Text, out t))
{
// successfully parsed
}
// or just use parse..
int f1 = Int32.Parse(textBox1.Text);
int t1 = Int32.Parse(textBox3.Text);
if (rangeCheck(f, t))
{
// Success
}
}
bool rangeCheck(int first, int third)
{
return (first >= 0 && first <= 100 && third >= 0 && third <= 100);
}
Код вашего дизайнера форм: измените в соответствии с вашими потребностями
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(230, 75);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 0;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(230, 123);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 1;
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(230, 168);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(100, 20);
this.textBox3.TabIndex = 2;
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(230, 211);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(100, 20);
this.textBox4.TabIndex = 3;
//
// button1
//
this.button1.Location = new System.Drawing.Point(230, 262);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 4;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click_1);
Используя WPF
<TextBox Name="box1" ...other_properties />
<TextBox Name="box2" ...other_properties />
<TextBox Name="box3" ...other_properties />
<TextBox Name="box4" ...other_properties />
<Button Click="Button_Click" Content="Check for validity" ...other properties />
Теперь обработайте те:
private void Button_Click(object sender, RoutedEventArgs e)
{
int f = 0, t = 0;
if (Int32.TryParse(box1.Text, out f))
{
// successfully parsed
}
if (Int32.TryParse(box3.Text, out t))
{
// successfully parsed
}
// or just use parse..
int f1 = Int32.Parse(box1.Text);
int t1 = Int32.Parse(box3.Text);
if (rangeCheck(f, t))
{
Debug.WriteLine("Both are within 0 and 100");
}
}
bool rangeCheck(int first, int third)
{
return (first >= 0 && first <= 100 && third >= 0 && third <= 100);
}