"форма 2" не передаёт значения "форме 1"
10.06.2014, 16:08. Показов 1417. Ответов 2
Есть 1 форма которая содержит 3 кнопки меню (menustrip): Input Color, Change, Clear. При нажатии на первую кнопку открывается 2-я форма, которая содержит 2 checkbox'a, 3 radioBatton и кнопку ОК. Надо сделать так что бы если пользователь поставил галочку в checkbox1 и нажал ОК, при нажатии Change выскакивал massageBox "f=1", если пользователь нажал на Input Color, но не поставил галочку в checkbox1, то при нажатии Change выскакивал massageBox "f=0".
У меня получается что f всегда = 0.
Вот мой код:
Form1.cs:
| 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
| 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 лаба_12си
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void inputColorToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.Show();
}
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
Graphics g = CreateGraphics();
g.FillRectangle(Brushes.White, 0, 0, 600, 600);
}
public void Form1_Load(object sender, EventArgs e)
{
}
public void changeToolStripMenuItem_Click(object sender, EventArgs e)
{
}
public void Form1_Paint(object sender, PaintEventArgs e)
{
}
public void changeToolStripMenuItem_Click_1(object sender, EventArgs e)
{
int f = 0, s = 0, k = 0, i = 0;
Form2 frm = new Form2();
Graphics g = CreateGraphics();
if (frm.checkBox1.Checked == true)
f = f + 1;
MessageBox.Show("f = "+f);
}
}
} |
|
Form1.Designer.cs:
| 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
| namespace лаба_12си
{
partial class Form1
{
/// <summary>
/// Требуется переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором форм Windows
/// <summary>
/// Обязательный метод для поддержки конструктора - не изменяйте
/// содержимое данного метода при помощи редактора кода.
/// </summary>
private void InitializeComponent()
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.inputColorToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.changeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.clearToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.inputColorToolStripMenuItem,
this.changeToolStripMenuItem,
this.clearToolStripMenuItem,
this.toolStripMenuItem1});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(302, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// inputColorToolStripMenuItem
//
this.inputColorToolStripMenuItem.Name = "inputColorToolStripMenuItem";
this.inputColorToolStripMenuItem.Size = new System.Drawing.Size(79, 20);
this.inputColorToolStripMenuItem.Text = "Input Color";
this.inputColorToolStripMenuItem.Click += new System.EventHandler(this.inputColorToolStripMenuItem_Click);
//
// changeToolStripMenuItem
//
this.changeToolStripMenuItem.Name = "changeToolStripMenuItem";
this.changeToolStripMenuItem.Size = new System.Drawing.Size(60, 20);
this.changeToolStripMenuItem.Text = "Change";
this.changeToolStripMenuItem.Click += new System.EventHandler(this.changeToolStripMenuItem_Click_1);
//
// clearToolStripMenuItem
//
this.clearToolStripMenuItem.Name = "clearToolStripMenuItem";
this.clearToolStripMenuItem.Size = new System.Drawing.Size(46, 20);
this.clearToolStripMenuItem.Text = "Clear";
this.clearToolStripMenuItem.Click += new System.EventHandler(this.clearToolStripMenuItem_Click);
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(12, 20);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ControlDark;
this.ClientSize = new System.Drawing.Size(302, 273);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.MaximumSize = new System.Drawing.Size(318, 312);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Ніколаєв Д.Ю., П-11, 11-Вариант";
this.Load += new System.EventHandler(this.Form1_Load);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
public System.Windows.Forms.MenuStrip menuStrip1;
public System.Windows.Forms.ToolStripMenuItem inputColorToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem clearToolStripMenuItem;
public System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1;
public System.Windows.Forms.ToolStripMenuItem changeToolStripMenuItem;
}
} |
|
Form2.cs:
| 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
| 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 лаба_12си
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public void checkBox2_CheckedChanged(object sender, EventArgs e)
{
}
public void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
public void radioButton1_CheckedChanged(object sender, EventArgs e)
{
}
public void radioButton2_CheckedChanged(object sender, EventArgs e)
{
}
public void radioButton3_CheckedChanged(object sender, EventArgs e)
{
}
public void button1_Click(object sender, EventArgs e)
{
Hide();
}
}
} |
|
Form2.Designer.cs:
| 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
| namespace лаба_12си
{
partial class Form2
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
public
void InitializeComponent()
{
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(192, 69);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(54, 17);
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "Down";
this.checkBox1.UseVisualStyleBackColor = true;
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.Location = new System.Drawing.Point(192, 22);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(40, 17);
this.checkBox2.TabIndex = 1;
this.checkBox2.Text = "Up";
this.checkBox2.UseVisualStyleBackColor = true;
this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Location = new System.Drawing.Point(12, 21);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(45, 17);
this.radioButton1.TabIndex = 2;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "Red";
this.radioButton1.UseVisualStyleBackColor = true;
this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
//
// radioButton2
//
this.radioButton2.AutoSize = true;
this.radioButton2.Location = new System.Drawing.Point(12, 44);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(54, 17);
this.radioButton2.TabIndex = 3;
this.radioButton2.TabStop = true;
this.radioButton2.Text = "Green";
this.radioButton2.UseVisualStyleBackColor = true;
this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
//
// radioButton3
//
this.radioButton3.AutoSize = true;
this.radioButton3.Location = new System.Drawing.Point(12, 69);
this.radioButton3.Name = "radioButton3";
this.radioButton3.Size = new System.Drawing.Size(46, 17);
this.radioButton3.TabIndex = 4;
this.radioButton3.TabStop = true;
this.radioButton3.Text = "Blue";
this.radioButton3.UseVisualStyleBackColor = true;
this.radioButton3.CheckedChanged += new System.EventHandler(this.radioButton3_CheckedChanged);
//
// button1
//
this.button1.BackColor = System.Drawing.SystemColors.Control;
this.button1.Location = new System.Drawing.Point(95, 41);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 5;
this.button1.Text = "OK";
this.button1.UseVisualStyleBackColor = false;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 110);
this.Controls.Add(this.button1);
this.Controls.Add(this.radioButton3);
this.Controls.Add(this.radioButton2);
this.Controls.Add(this.radioButton1);
this.Controls.Add(this.checkBox2);
this.Controls.Add(this.checkBox1);
this.Name = "Form2";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Input Color";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
public System.Windows.Forms.CheckBox checkBox1;
public System.Windows.Forms.CheckBox checkBox2;
public System.Windows.Forms.RadioButton radioButton1;
public System.Windows.Forms.RadioButton radioButton2;
public System.Windows.Forms.RadioButton radioButton3;
private System.Windows.Forms.Button button1;
}
} |
|
0
|