Using a timer in visual studio

So I have been trying to get a timer to work in visual studio and for some reason when the timer runs it only runs once. In the properties the interval is set to 1000 and enabled is set to false. I tried to set enabled to true and that doesn't work.

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
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;
using System.IO;
using System.Threading;




namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        public int pausevar = 0;
 
        public Form1()
        {
            InitializeComponent();
            
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            CreateBitmap();
            timer1.Start();
             }
                              
        void CreateBitmap()
        {
            System.Drawing.Bitmap flag = new System.Drawing.Bitmap(700, 700);
            for (int x = 0; x < 625; ++x)
                for (int y = 0; y < 320; ++y)
                    flag.SetPixel(x, y, Color.Black);          
            pictureBox1.Image = flag;
        }

        private void Pause_Click(object sender, EventArgs e)
        {
            Pause.Visible = false;
            Continue.Visible = true;

            pausevar = 1;
        }

        private void Start_Click(object sender, EventArgs e)
        {
           
            Pause.Visible = true;
            Start.Visible = false;
            runthestuff();
           
        }

        private void Continue_Click(object sender, EventArgs e)
        {
            Pause.Visible = true;
            Continue.Visible = false;

            pausevar = 0;
        }
        void runthestuff()
        {
           

            }
        

        private void timer1_Tick(object sender, EventArgs e)
        {
            System.Drawing.Bitmap flag = new System.Drawing.Bitmap(700, 700);

            int i;

            i = 0;

            if (pausevar == 0)
            {
                if (i == 0)
                {
                    for (int x = 0; x < 625; ++x)
                        for (int y = 0; y < 320; ++y)
                            flag.SetPixel(x, y, Color.Red);
                    pictureBox1.Image = flag;
                    i = 1;
                }
                else if (i == 1)
                {
                    System.Threading.Thread.Sleep(50);
                    for (int x = 0; x < 625; ++x)
                        for (int y = 0; y < 320; ++y)
                            flag.SetPixel(x, y, Color.Blue);
                    pictureBox1.Image = flag;
                    System.Threading.Thread.Sleep(50);
                    i = 0;
                }
            }
        }

        
    }
}
Last edited on
Topic archived. No new replies allowed.