Witam. Mam pytanie. Probuje oprogramowac textboxy tak, zeby po przeskoczeniu do kolejnego wykonywalo instrukcje. Jak to zrobic? Probowalem cos z KeyUp ale nie do konca wiem jak to dziala.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace For_homework
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var LoopResult = new List<int>();
var LoopParameters = new List<int>();
LoopParameters = TakeInput();
LoopResult = Looping(LoopParameters);
Result(LoopResult);
FinalResult(LoopResult);
}
private List<int> TakeInput()
{
var Loop = new List<int>();
Loop.Add(int.Parse(textBox1.Text));
Loop.Add(int.Parse(textBox2.Text));
Loop.Add(int.Parse(textBox3.Text));
Loop.Add(int.Parse(textBox4.Text));
Loop.Add(int.Parse(textBox5.Text));
Loop.Add(int.Parse(textBox6.Text));
return Loop;
}//Take the input
private List<int> Looping(List<int> LoopParam)
{
var LoopSum = new List<int>();
LoopSum.Add(0);
LoopSum.Add(0);
for (int i = LoopParam[0]; i <= LoopParam[1]; i += LoopParam[2])
{
LoopSum[0]+=i;
}
for(int i = LoopParam[3]; i <= LoopParam[4]; i += LoopParam[5])
{
LoopSum[1]+=i;
}
return LoopSum;
}//Do the loop and summarize
void Result (List<int> LoopResult)
{
resultA.Text = ""+LoopResult[0];
resultB.Text = ""+LoopResult[1];
}//Give result
void FinalResult(List<int> LoopResult)
{
if(LoopResult[0]>LoopResult[1])
{
WhoWins.Text = "Player A wins";
}
else if(LoopResult[1]>LoopResult[0])
{
WhoWins.Text = "Player B wins";
}
else
{
WhoWins.Text = "It's a draw";
}
}//Give final result
private void textBox1_TextChanged(object sender, EventArgs e)
{
int i = int.Parse(textBox1.Text);
if (i < 1 || i > 6)
label3.Text = "Wrong number";
}//Texbox evaluation
private void textBox2_TextChanged(object sender, EventArgs e)
{
int i = int.Parse(textBox2.Text);
if (i < 7 || i > 18)
label4.Text = "Wrong number";
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
int i = int.Parse(textBox4.Text);
if (i < 1 || i > 6)
label7.Text = "Wrong number";
}//Textbox evaluation
private void textBox5_TextChanged(object sender, EventArgs e)
{
int i = int.Parse(textBox5.Text);
if (i < 7 || i > 18)
label8.Text = "Wrong number";
}
}
}