Hi all
I have the following code: a line is growing up by clicking on "up" button, it has another button"start" which I want it to stop the process of growing the line...How can I make a button to stop the process of another button?
class Program: Form
{
int x1;
int y1;
int x2;
int y2;
Button up = new Button();
Button start = new Button();
public Program()
{
Size=new Size(800,800);
x1 = 365;
y1 = 280;
x2 = 365;
y2 = 280;
/*Create Buttons*/
up.Text = "Up";
up.Click += new EventHandler(up_Click);
up.Location = new Point(340, 550);
up.Size = new Size(100, 40);
this.Controls.Add(up);
start.Text = "Start/"+"\n"+"Pause";
start.Click += new EventHandler(start_Click);
start.Location = new Point(340, 600);
start.Size = new Size(100, 40);
this.Controls.Add(start);
this.Paint += new PaintEventHandler(myform_Paint);
}
void up_Click(object sender, EventArgs e)
{
AnimateUp();
}
void start_Click(object sender, EventArgs e)
{
AnimateStart();
}
private void AnimateUp()
{
if (start.Text == "Assume")
start.Text = "Pause";
{
while (y2 > 24)
{
y2 = y2 - 10;
this.Invalidate();
this.Refresh();
System.Threading.Thread.Sleep(100);
}
x1 = x2;
y1 = y2;
MessageBox.Show("Game Over!!", "End of the game", MessageBoxButtons.OKCancel);
Application.Exit();
}
}
private void AnimateStart()
{
if (start.Text == "Start/" + "\n" + "Pause")
start.Text = "Pause";
else if (start.Text == "Pause")
start.Text = "Assume";
}
private void myform_Paint( object sender,PaintEventArgs e)
{
Graphics g = e.Graphics;
Brush brush = new SolidBrush(Color.Black);
Pen pen = new Pen(brush, 4);
g.DrawRectangle(pen, 20, 20, 750, 500);
g.DrawLine(pen, x1, y1,x2, y2);
}
static void Main(string[] args)
{
Application.Run(new Program());
Application.Exit();
}