I suppose you have some code that you are calling for drawing the line? Why don't you post that? Basically a bool flag should be able to do the job. The line continues to be drawn while the bool flag is true. If the Pause button is pressed, change the value of your boolean flag.
I tries a flag,the problem is pause button isnt active while the line is growing...I'll copy the code..."Up"button makes the line grow up, and "start" button should make it stop.
class Program: Form
{
int x1;
int y1;
int x2;
int y2;
Button up = new Button();
bool upFlag = true;
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 (upFlag == true)
{
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(upFlag==true)
upFlag = false;
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();
}