Проблема:
При нажатии желтой кнопки (Form2.button2) Планировалось "откладывание" таймера. Тое сть ожидалось, что 1 таймер сработает через указанное в текстбоксе на второй форме время. Остальные сработают через время указанное на первой форме+время из текстбокса второй формы.
При тесте произошло следующее:
При срабатывании первого таймера время отложили на минуту. Первый таймер через минуту не сработал, сработал второй. Еще через минуту повторно сработал второй, а третий так и не сработал.
Как это выглядит:
Форма 1:
Форма 2:
Код первой формы:
C# |
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
110
111
112
| namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = "Поехали!";
label2.Visible = false;
label3.Visible = false;
timer1.Interval = Int32.Parse(textBox4.Text) * 1000 * 60;
timer1.Start();
if (textBox2.Visible)
{
timer2.Interval = Int32.Parse(textBox5.Text) * 1000 * 60+timer1.Interval;
timer2.Start();
if (textBox3.Visible)
{
timer3.Interval = Int32.Parse(textBox6.Text) * 1000 * 60 + timer2.Interval;
timer3.Start();
}
}
label1.Visible = true;
button1.Text = "На меня уже нажали:с";
button4.Visible = true;
button3.Enabled = false;
button2.Enabled = false;
textBox1.Enabled = false;
textBox2.Enabled = false;
textBox3.Enabled = false;
textBox4.Enabled = false;
textBox5.Enabled = false;
textBox6.Enabled = false;
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "Введи тут время ";
}
private void timer1_Tick(object sender, EventArgs e) {
timer1.Enabled = false;
Form2 f = new Form2(this.textBox1.Text);
f.Owner = this;
f.ShowDialog();
}
private void button2_Click(object sender, EventArgs e)
{
textBox2.Visible = true;
textBox5.Visible = true;
button3.Visible = true;
}
private void button3_Click(object sender, EventArgs e)
{
textBox3.Visible = true;
textBox6.Visible = true;
}
private void timer2_Tick(object sender, EventArgs e)
{
timer2.Enabled = false;
Form2 f = new WindowsFormsApplication2.Form2(this.textBox2.Text);
f.ShowDialog();
}
private void timer3_Tick(object sender, EventArgs e)
{
timer3.Enabled = false;
Form2 f = new WindowsFormsApplication2.Form2(this.textBox2.Text);
f.ShowDialog();
}
private void button4_Click(object sender, EventArgs e)
{
button4.Visible = false;
button3.Enabled = true;
button2.Enabled = true;
textBox1.Enabled = true;
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox5.Enabled = true;
textBox6.Enabled = true;
timer1.Enabled = false;
timer2.Enabled = false;
timer3.Enabled = false;
label2.Visible = true;
label3.Visible = true;
label1.Visible = false;
button1.Text = ("Попробуем еще;)");
}
private void Form1_Load_1(object sender, EventArgs e)
{
}
}
} |
|
Код второй:
C# |
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
| namespace WindowsFormsApplication2
{
public partial class Form2 : Form
{
public Form2(string message)
{
InitializeComponent();
this.label2.Text = message;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
this.Visible = false;
}
private void button2_Click(object sender, EventArgs e)//Продлить интервал
{
Form1 main = this.Owner as Form1;//Объяснили где родительская форма
{
if (Equals(label2.Text,main.textBox1))//Проверяем какой это вызов формы.1
{
main.timer1.Interval = Int32.Parse(textBox1.Text) * 60 * 1000;
main.timer1.Enabled = true;//Запускаем таймер с доп. интервалом
if (main.button2.Visible)
{
main.timer2.Interval += Int32.Parse(textBox1.Text) * 60 * 1000;
if (main.button3.Visible)
{
main.timer3.Interval += Int32.Parse(textBox1.Text) * 60 * 1000;
}
}
}
if (Equals(label2.Text,main.textBox2))//Проверяем какой это вызов формы.2
{
main.timer2.Interval = Int32.Parse(textBox1.Text) * 60 * 1000;
main.timer2.Enabled = true;//Запускаем таймер с доп. интервалом
if (main.button3.Visible)
{
main.timer3.Interval += Int32.Parse(textBox1.Text) * 60 * 1000;
}
}
if (Equals(label2.Text,main.textBox3))//Проверяем какой это вызов формы.3
{
main.timer3.Interval = Int32.Parse(textBox1.Text) * 60 * 1000;
main.timer3.Enabled = true; //Запускаем таймер с доп. интервалом
}
}
this.Visible = false; //Ну и спрятали эту форму до следующего раза
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.Visible = false;
} |
|