質問するログイン新規登録

回答編集履歴

3

見直しキャンペーン中

2023/07/23 06:43

投稿

TN8001
TN8001

スコア10180

answer CHANGED
@@ -1,238 +1,235 @@
1
- `Application.Run(Form1.GetInstance());`
2
- こうしてください。
3
-
4
- ---
5
-
6
- 今の状況というか問題点は、
7
- 1. メインフォームとサブフォーム1-13は既にできていて、動作自体に問題はない
8
- 2. サブフォームを排他的(どれか一つだけしか開けないよう)に改造しようとしている
9
- 3. その際地道にやれば(コメントアウトのコード)できることはわかっている
10
- 4. しかし13個はだるいし、もっといい方法がありそうに思える
11
-
12
- ってことですよね?(実際2個目くらいでもうだるかったです^^;
13
-
14
- 自分だったらこうするかなぁ?ってコードです。
15
- `button1_Click`もまとめてもよさそうですが、行数も減りそうにないのでそのまま。
16
-
17
- Form1.cs
18
- ```C#
19
- using System;
20
- using System.Drawing;
21
- using System.Windows.Forms;
22
-
23
- namespace Questions293390
24
- {
25
- public partial class Form1 : Form
26
- {
27
- // シングルトンの必要はないかもしれないが、どうせSubFormからForm1をいじりたくなりますよね?
28
- public static Form1 Instance { get; } = new Form1();
29
-
30
- private Form1() => InitializeComponent();
31
-
32
- private void button1_Click(object sender, EventArgs e)
33
- => ShowSubForm(new SubForm1(), panel1);
34
-
35
- private void button2_Click(object sender, EventArgs e)
36
- => ShowSubForm(new SubForm2(), panel1);
37
-
38
- private void button3_Click(object sender, EventArgs e)
39
- => ShowSubForm(new SubForm3(), panel1);
40
-
41
- // class Commonにあっても別に構わない
42
- private static void ShowSubForm(Form subForm, Panel group)
43
- {
44
- // Panel配下のボタンを不活性
45
- foreach(var control in group.Controls)
46
- {
47
- if(control is Button button)
48
- button.Enabled = false;
49
- }
50
-
51
- // SubFormのクローズを購読
52
- subForm.FormClosed += SubForm_FormClosed;
53
- // PanelをTagに入れて覚えておく
54
- subForm.Tag = group;
55
- subForm.Show();
56
- }
57
-
58
- // クローズ時にPanel配下のボタンを戻す
59
- private static void SubForm_FormClosed(object sender, FormClosedEventArgs e)
60
- {
61
- // senderはSubForm自身
62
- if(sender is Form subForm)
63
- {
64
- // PanelをTagから取り出す
65
- if(subForm.Tag is Panel group)
66
- {
67
- foreach(var control in group.Controls)
68
- {
69
- if(control is Button button)
70
- button.Enabled = true;
71
- }
72
- }
73
- }
74
- }
75
- }
76
-
77
- // SubFormでFormClosed等のイベントを書く必要がなくて楽々という意味
78
- // 実際は普通に作る
79
- public class SubForm1 : Form
80
- {
81
- public SubForm1() { Text = "SubForm1"; ClientSize = new Size(300, 200); }
82
- }
83
- public class SubForm2 : Form
84
- {
85
- public SubForm2() { Text = "SubForm2"; ClientSize = new Size(300, 200); }
86
- }
87
- public class SubForm3 : Form
88
- {
89
- public SubForm3() { Text = "SubForm3"; ClientSize = new Size(300, 200); }
90
- }
91
- }
92
- ```
93
-
94
- Form1.Designer.cs
95
- ```C#
96
- namespace Questions293390
97
- {
98
- partial class Form1
99
- {
100
- /// <summary>
101
- /// 必要なデザイナー変数です。
102
- /// </summary>
103
- private System.ComponentModel.IContainer components = null;
104
-
105
- /// <summary>
106
- /// 使用中のリソースをすべてクリーンアップします。
107
- /// </summary>
108
- /// <param name="disposing">マネージド リソースを破棄する場合は true を指定し、その他の場合は false を指定します。</param>
109
- protected override void Dispose(bool disposing)
110
- {
111
- if(disposing && (components != null))
112
- {
113
- components.Dispose();
114
- }
115
- base.Dispose(disposing);
116
- }
117
-
118
- #region Windows フォーム デザイナーで生成されたコード
119
-
120
- /// <summary>
121
- /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
122
- /// コード エディターで変更しないでください。
123
- /// </summary>
124
- private void InitializeComponent()
125
- {
126
- this.button1 = new System.Windows.Forms.Button();
127
- this.button2 = new System.Windows.Forms.Button();
128
- this.button3 = new System.Windows.Forms.Button();
129
- this.panel1 = new System.Windows.Forms.Panel();
130
- this.otherButton = new System.Windows.Forms.Button();
131
- this.label1 = new System.Windows.Forms.Label();
132
- this.panel1.SuspendLayout();
133
- this.SuspendLayout();
134
- //
135
- // button1
136
- //
137
- this.button1.Location = new System.Drawing.Point(5, 34);
138
- this.button1.Name = "button1";
139
- this.button1.Size = new System.Drawing.Size(75, 23);
140
- this.button1.TabIndex = 0;
141
- this.button1.Text = "button1";
142
- this.button1.UseVisualStyleBackColor = true;
143
- this.button1.Click += new System.EventHandler(this.button1_Click);
144
- //
145
- // button2
146
- //
147
- this.button2.Location = new System.Drawing.Point(5, 63);
148
- this.button2.Name = "button2";
149
- this.button2.Size = new System.Drawing.Size(75, 23);
150
- this.button2.TabIndex = 1;
151
- this.button2.Text = "button2";
152
- this.button2.UseVisualStyleBackColor = true;
153
- this.button2.Click += new System.EventHandler(this.button2_Click);
154
- //
155
- // button3
156
- //
157
- this.button3.Location = new System.Drawing.Point(5, 92);
158
- this.button3.Name = "button3";
159
- this.button3.Size = new System.Drawing.Size(75, 23);
160
- this.button3.TabIndex = 2;
161
- this.button3.Text = "button3";
162
- this.button3.UseVisualStyleBackColor = true;
163
- this.button3.Click += new System.EventHandler(this.button3_Click);
164
- //
165
- // panel1
166
- //
167
- this.panel1.Controls.Add(this.label1);
168
- this.panel1.Controls.Add(this.button3);
169
- this.panel1.Controls.Add(this.button1);
170
- this.panel1.Controls.Add(this.button2);
171
- this.panel1.Location = new System.Drawing.Point(153, 136);
172
- this.panel1.Name = "panel1";
173
- this.panel1.Size = new System.Drawing.Size(112, 125);
174
- this.panel1.TabIndex = 3;
175
- //
176
- // otherButton
177
- //
178
- this.otherButton.Location = new System.Drawing.Point(538, 54);
179
- this.otherButton.Name = "otherButton";
180
- this.otherButton.Size = new System.Drawing.Size(75, 23);
181
- this.otherButton.TabIndex = 4;
182
- this.otherButton.Text = "otherButton";
183
- this.otherButton.UseVisualStyleBackColor = true;
184
- //
185
- // label1
186
- //
187
- this.label1.AutoSize = true;
188
- this.label1.Location = new System.Drawing.Point(3, 10);
189
- this.label1.Name = "label1";
190
- this.label1.Size = new System.Drawing.Size(35, 12);
191
- this.label1.TabIndex = 3;
192
- this.label1.Text = "label1";
193
- //
194
- // Form1
195
- //
196
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
197
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
198
- this.ClientSize = new System.Drawing.Size(800, 450);
199
- this.Controls.Add(this.otherButton);
200
- this.Controls.Add(this.panel1);
201
- this.Name = "Form1";
202
- this.Text = "Form1";
203
- this.panel1.ResumeLayout(false);
204
- this.panel1.PerformLayout();
205
- this.ResumeLayout(false);
206
-
207
- }
208
-
209
- #endregion
210
- private System.Windows.Forms.Label label1;
211
- private System.Windows.Forms.Button otherButton;
212
- private System.Windows.Forms.Button button1;
213
- private System.Windows.Forms.Button button2;
214
- private System.Windows.Forms.Button button3;
215
- private System.Windows.Forms.Panel panel1;
216
- }
217
- }
218
- ```
219
-
220
- Program.cs
221
- ```C#
222
- using System;
223
- using System.Windows.Forms;
224
-
225
- namespace Questions293390
226
- {
227
- static class Program
228
- {
229
- [STAThread]
230
- static void Main()
231
- {
232
- Application.EnableVisualStyles();
233
- Application.SetCompatibleTextRenderingDefault(false);
234
- Application.Run(Form1.Instance);
235
- }
236
- }
237
- }
1
+ `Application.Run(Form1.GetInstance());`
2
+ こうしてください。
3
+
4
+ ---
5
+
6
+ 今の状況というか問題点は、
7
+ 1. メインフォームとサブフォーム1-13は既にできていて、動作自体に問題はない
8
+ 2. サブフォームを排他的(どれか一つだけしか開けないよう)に改造しようとしている
9
+ 3. その際地道にやれば(コメントアウトのコード)できることはわかっている
10
+ 4. しかし13個はだるいし、もっといい方法がありそうに思える
11
+
12
+ ってことですよね?(実際2個目くらいでもうだるかったです^^;
13
+
14
+ 自分だったらこうするかなぁ?ってコードです。
15
+ `button1_Click`もまとめてもよさそうですが、行数も減りそうにないのでそのまま。
16
+
17
+ ```cs:Form1.cs
18
+ using System;
19
+ using System.Drawing;
20
+ using System.Windows.Forms;
21
+
22
+ namespace Questions293390
23
+ {
24
+ public partial class Form1 : Form
25
+ {
26
+ // シングルトンの必要はないかもしれないが、どうせSubFormからForm1をいじりたくなりますよね?
27
+ public static Form1 Instance { get; } = new Form1();
28
+
29
+ private Form1() => InitializeComponent();
30
+
31
+ private void button1_Click(object sender, EventArgs e)
32
+ => ShowSubForm(new SubForm1(), panel1);
33
+
34
+ private void button2_Click(object sender, EventArgs e)
35
+ => ShowSubForm(new SubForm2(), panel1);
36
+
37
+ private void button3_Click(object sender, EventArgs e)
38
+ => ShowSubForm(new SubForm3(), panel1);
39
+
40
+ // class Commonにあっても別に構わない
41
+ private static void ShowSubForm(Form subForm, Panel group)
42
+ {
43
+ // Panel配下のボタンを不活性
44
+ foreach(var control in group.Controls)
45
+ {
46
+ if(control is Button button)
47
+ button.Enabled = false;
48
+ }
49
+
50
+ // SubFormのクローズを購読
51
+ subForm.FormClosed += SubForm_FormClosed;
52
+ // PanelをTagに入れて覚えておく
53
+ subForm.Tag = group;
54
+ subForm.Show();
55
+ }
56
+
57
+ // クローズ時にPanel配下のボタンを戻す
58
+ private static void SubForm_FormClosed(object sender, FormClosedEventArgs e)
59
+ {
60
+ // senderはSubForm自身
61
+ if(sender is Form subForm)
62
+ {
63
+ // PanelをTagから取り出す
64
+ if(subForm.Tag is Panel group)
65
+ {
66
+ foreach(var control in group.Controls)
67
+ {
68
+ if(control is Button button)
69
+ button.Enabled = true;
70
+ }
71
+ }
72
+ }
73
+ }
74
+ }
75
+
76
+ // SubFormではFormClosed等のイベントを書く必要がなくて楽々という意味
77
+ // 実際普通に作る
78
+ public class SubForm1 : Form
79
+ {
80
+ public SubForm1() { Text = "SubForm1"; ClientSize = new Size(300, 200); }
81
+ }
82
+ public class SubForm2 : Form
83
+ {
84
+ public SubForm2() { Text = "SubForm2"; ClientSize = new Size(300, 200); }
85
+ }
86
+ public class SubForm3 : Form
87
+ {
88
+ public SubForm3() { Text = "SubForm3"; ClientSize = new Size(300, 200); }
89
+ }
90
+ }
91
+ ```
92
+
93
+ ```cs:Form1.Designer.cs
94
+ namespace Questions293390
95
+ {
96
+ partial class Form1
97
+ {
98
+ /// <summary>
99
+ /// 必要なデザイナー変数です。
100
+ /// </summary>
101
+ private System.ComponentModel.IContainer components = null;
102
+
103
+ /// <summary>
104
+ /// 使用中のリソースをすべてクリーンアップします。
105
+ /// </summary>
106
+ /// <param name="disposing">マネージド リソースを破棄る場合は true を指定、その他の場合は false を指定します。</param>
107
+ protected override void Dispose(bool disposing)
108
+ {
109
+ if(disposing && (components != null))
110
+ {
111
+ components.Dispose();
112
+ }
113
+ base.Dispose(disposing);
114
+ }
115
+
116
+ #region Windows フォーム デザイナーで生成されたコード
117
+
118
+ /// <summary>
119
+ /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
120
+ /// コード エディターで変更しないでください。
121
+ /// </summary>
122
+ private void InitializeComponent()
123
+ {
124
+ this.button1 = new System.Windows.Forms.Button();
125
+ this.button2 = new System.Windows.Forms.Button();
126
+ this.button3 = new System.Windows.Forms.Button();
127
+ this.panel1 = new System.Windows.Forms.Panel();
128
+ this.otherButton = new System.Windows.Forms.Button();
129
+ this.label1 = new System.Windows.Forms.Label();
130
+ this.panel1.SuspendLayout();
131
+ this.SuspendLayout();
132
+ //
133
+ // button1
134
+ //
135
+ this.button1.Location = new System.Drawing.Point(5, 34);
136
+ this.button1.Name = "button1";
137
+ this.button1.Size = new System.Drawing.Size(75, 23);
138
+ this.button1.TabIndex = 0;
139
+ this.button1.Text = "button1";
140
+ this.button1.UseVisualStyleBackColor = true;
141
+ this.button1.Click += new System.EventHandler(this.button1_Click);
142
+ //
143
+ // button2
144
+ //
145
+ this.button2.Location = new System.Drawing.Point(5, 63);
146
+ this.button2.Name = "button2";
147
+ this.button2.Size = new System.Drawing.Size(75, 23);
148
+ this.button2.TabIndex = 1;
149
+ this.button2.Text = "button2";
150
+ this.button2.UseVisualStyleBackColor = true;
151
+ this.button2.Click += new System.EventHandler(this.button2_Click);
152
+ //
153
+ // button3
154
+ //
155
+ this.button3.Location = new System.Drawing.Point(5, 92);
156
+ this.button3.Name = "button3";
157
+ this.button3.Size = new System.Drawing.Size(75, 23);
158
+ this.button3.TabIndex = 2;
159
+ this.button3.Text = "button3";
160
+ this.button3.UseVisualStyleBackColor = true;
161
+ this.button3.Click += new System.EventHandler(this.button3_Click);
162
+ //
163
+ // panel1
164
+ //
165
+ this.panel1.Controls.Add(this.label1);
166
+ this.panel1.Controls.Add(this.button3);
167
+ this.panel1.Controls.Add(this.button1);
168
+ this.panel1.Controls.Add(this.button2);
169
+ this.panel1.Location = new System.Drawing.Point(153, 136);
170
+ this.panel1.Name = "panel1";
171
+ this.panel1.Size = new System.Drawing.Size(112, 125);
172
+ this.panel1.TabIndex = 3;
173
+ //
174
+ // otherButton
175
+ //
176
+ this.otherButton.Location = new System.Drawing.Point(538, 54);
177
+ this.otherButton.Name = "otherButton";
178
+ this.otherButton.Size = new System.Drawing.Size(75, 23);
179
+ this.otherButton.TabIndex = 4;
180
+ this.otherButton.Text = "otherButton";
181
+ this.otherButton.UseVisualStyleBackColor = true;
182
+ //
183
+ // label1
184
+ //
185
+ this.label1.AutoSize = true;
186
+ this.label1.Location = new System.Drawing.Point(3, 10);
187
+ this.label1.Name = "label1";
188
+ this.label1.Size = new System.Drawing.Size(35, 12);
189
+ this.label1.TabIndex = 3;
190
+ this.label1.Text = "label1";
191
+ //
192
+ // Form1
193
+ //
194
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
195
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
196
+ this.ClientSize = new System.Drawing.Size(800, 450);
197
+ this.Controls.Add(this.otherButton);
198
+ this.Controls.Add(this.panel1);
199
+ this.Name = "Form1";
200
+ this.Text = "Form1";
201
+ this.panel1.ResumeLayout(false);
202
+ this.panel1.PerformLayout();
203
+ this.ResumeLayout(false);
204
+
205
+ }
206
+
207
+ #endregion
208
+ private System.Windows.Forms.Label label1;
209
+ private System.Windows.Forms.Button otherButton;
210
+ private System.Windows.Forms.Button button1;
211
+ private System.Windows.Forms.Button button2;
212
+ private System.Windows.Forms.Button button3;
213
+ private System.Windows.Forms.Panel panel1;
214
+ }
215
+ }
216
+ ```
217
+
218
+ ```cs:Program.cs
219
+ using System;
220
+ using System.Windows.Forms;
221
+
222
+ namespace Questions293390
223
+ {
224
+ static class Program
225
+ {
226
+ [STAThread]
227
+ static void Main()
228
+ {
229
+ Application.EnableVisualStyles();
230
+ Application.SetCompatibleTextRenderingDefault(false);
231
+ Application.Run(Form1.Instance);
232
+ }
233
+ }
234
+ }
238
235
  ```

2

メソッド化

2020/09/27 08:30

投稿

TN8001
TN8001

スコア10180

answer CHANGED
@@ -41,25 +41,34 @@
41
41
  // class Commonにあっても別に構わない
42
42
  private static void ShowSubForm(Form subForm, Panel group)
43
43
  {
44
- // group配下のボタンを不活性
44
+ // Panel配下のボタンを不活性
45
45
  foreach(var control in group.Controls)
46
46
  {
47
47
  if(control is Button button)
48
48
  button.Enabled = false;
49
49
  }
50
50
 
51
+ // SubFormのクローズを購読
51
- subForm.FormClosed += Closed;
52
+ subForm.FormClosed += SubForm_FormClosed;
53
+ // PanelをTagに入れて覚えておく
54
+ subForm.Tag = group;
52
55
  subForm.Show();
56
+ }
53
57
 
54
- // クローズ時にgroup配下のボタンを活性に戻す
58
+ // クローズ時にPanel配下のボタンを戻す
55
- void Closed(object sender, FormClosedEventArgs e)
59
+ private static void SubForm_FormClosed(object sender, FormClosedEventArgs e)
60
+ {
61
+ // senderはSubForm自身
62
+ if(sender is Form subForm)
56
63
  {
64
+ // PanelをTagから取り出す
57
- subForm.FormClosed -= Closed;
65
+ if(subForm.Tag is Panel group)
58
-
59
- foreach(var control in group.Controls)
60
66
  {
67
+ foreach(var control in group.Controls)
68
+ {
61
- if(control is Button button)
69
+ if(control is Button button)
62
- button.Enabled = true;
70
+ button.Enabled = true;
71
+ }
63
72
  }
64
73
  }
65
74
  }

1

コード追記

2020/09/27 08:30

投稿

TN8001
TN8001

スコア10180

answer CHANGED
@@ -1,2 +1,229 @@
1
1
  `Application.Run(Form1.GetInstance());`
2
- こうしてください。
2
+ こうしてください。
3
+
4
+ ---
5
+
6
+ 今の状況というか問題点は、
7
+ 1. メインフォームとサブフォーム1-13は既にできていて、動作自体に問題はない
8
+ 2. サブフォームを排他的(どれか一つだけしか開けないよう)に改造しようとしている
9
+ 3. その際地道にやれば(コメントアウトのコード)できることはわかっている
10
+ 4. しかし13個はだるいし、もっといい方法がありそうに思える
11
+
12
+ ってことですよね?(実際2個目くらいでもうだるかったです^^;
13
+
14
+ 自分だったらこうするかなぁ?ってコードです。
15
+ `button1_Click`もまとめてもよさそうですが、行数も減りそうにないのでそのまま。
16
+
17
+ Form1.cs
18
+ ```C#
19
+ using System;
20
+ using System.Drawing;
21
+ using System.Windows.Forms;
22
+
23
+ namespace Questions293390
24
+ {
25
+ public partial class Form1 : Form
26
+ {
27
+ // シングルトンの必要はないかもしれないが、どうせSubFormからForm1をいじりたくなりますよね?
28
+ public static Form1 Instance { get; } = new Form1();
29
+
30
+ private Form1() => InitializeComponent();
31
+
32
+ private void button1_Click(object sender, EventArgs e)
33
+ => ShowSubForm(new SubForm1(), panel1);
34
+
35
+ private void button2_Click(object sender, EventArgs e)
36
+ => ShowSubForm(new SubForm2(), panel1);
37
+
38
+ private void button3_Click(object sender, EventArgs e)
39
+ => ShowSubForm(new SubForm3(), panel1);
40
+
41
+ // class Commonにあっても別に構わない
42
+ private static void ShowSubForm(Form subForm, Panel group)
43
+ {
44
+ // group配下のボタンを不活性
45
+ foreach(var control in group.Controls)
46
+ {
47
+ if(control is Button button)
48
+ button.Enabled = false;
49
+ }
50
+
51
+ subForm.FormClosed += Closed;
52
+ subForm.Show();
53
+
54
+ // クローズ時にgroup配下のボタンを活性に戻す
55
+ void Closed(object sender, FormClosedEventArgs e)
56
+ {
57
+ subForm.FormClosed -= Closed;
58
+
59
+ foreach(var control in group.Controls)
60
+ {
61
+ if(control is Button button)
62
+ button.Enabled = true;
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ // SubFormではFormClosed等のイベントを書く必要がなくて楽々という意味
69
+ // 実際は普通に作る
70
+ public class SubForm1 : Form
71
+ {
72
+ public SubForm1() { Text = "SubForm1"; ClientSize = new Size(300, 200); }
73
+ }
74
+ public class SubForm2 : Form
75
+ {
76
+ public SubForm2() { Text = "SubForm2"; ClientSize = new Size(300, 200); }
77
+ }
78
+ public class SubForm3 : Form
79
+ {
80
+ public SubForm3() { Text = "SubForm3"; ClientSize = new Size(300, 200); }
81
+ }
82
+ }
83
+ ```
84
+
85
+ Form1.Designer.cs
86
+ ```C#
87
+ namespace Questions293390
88
+ {
89
+ partial class Form1
90
+ {
91
+ /// <summary>
92
+ /// 必要なデザイナー変数です。
93
+ /// </summary>
94
+ private System.ComponentModel.IContainer components = null;
95
+
96
+ /// <summary>
97
+ /// 使用中のリソースをすべてクリーンアップします。
98
+ /// </summary>
99
+ /// <param name="disposing">マネージド リソースを破棄する場合は true を指定し、その他の場合は false を指定します。</param>
100
+ protected override void Dispose(bool disposing)
101
+ {
102
+ if(disposing && (components != null))
103
+ {
104
+ components.Dispose();
105
+ }
106
+ base.Dispose(disposing);
107
+ }
108
+
109
+ #region Windows フォーム デザイナーで生成されたコード
110
+
111
+ /// <summary>
112
+ /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
113
+ /// コード エディターで変更しないでください。
114
+ /// </summary>
115
+ private void InitializeComponent()
116
+ {
117
+ this.button1 = new System.Windows.Forms.Button();
118
+ this.button2 = new System.Windows.Forms.Button();
119
+ this.button3 = new System.Windows.Forms.Button();
120
+ this.panel1 = new System.Windows.Forms.Panel();
121
+ this.otherButton = new System.Windows.Forms.Button();
122
+ this.label1 = new System.Windows.Forms.Label();
123
+ this.panel1.SuspendLayout();
124
+ this.SuspendLayout();
125
+ //
126
+ // button1
127
+ //
128
+ this.button1.Location = new System.Drawing.Point(5, 34);
129
+ this.button1.Name = "button1";
130
+ this.button1.Size = new System.Drawing.Size(75, 23);
131
+ this.button1.TabIndex = 0;
132
+ this.button1.Text = "button1";
133
+ this.button1.UseVisualStyleBackColor = true;
134
+ this.button1.Click += new System.EventHandler(this.button1_Click);
135
+ //
136
+ // button2
137
+ //
138
+ this.button2.Location = new System.Drawing.Point(5, 63);
139
+ this.button2.Name = "button2";
140
+ this.button2.Size = new System.Drawing.Size(75, 23);
141
+ this.button2.TabIndex = 1;
142
+ this.button2.Text = "button2";
143
+ this.button2.UseVisualStyleBackColor = true;
144
+ this.button2.Click += new System.EventHandler(this.button2_Click);
145
+ //
146
+ // button3
147
+ //
148
+ this.button3.Location = new System.Drawing.Point(5, 92);
149
+ this.button3.Name = "button3";
150
+ this.button3.Size = new System.Drawing.Size(75, 23);
151
+ this.button3.TabIndex = 2;
152
+ this.button3.Text = "button3";
153
+ this.button3.UseVisualStyleBackColor = true;
154
+ this.button3.Click += new System.EventHandler(this.button3_Click);
155
+ //
156
+ // panel1
157
+ //
158
+ this.panel1.Controls.Add(this.label1);
159
+ this.panel1.Controls.Add(this.button3);
160
+ this.panel1.Controls.Add(this.button1);
161
+ this.panel1.Controls.Add(this.button2);
162
+ this.panel1.Location = new System.Drawing.Point(153, 136);
163
+ this.panel1.Name = "panel1";
164
+ this.panel1.Size = new System.Drawing.Size(112, 125);
165
+ this.panel1.TabIndex = 3;
166
+ //
167
+ // otherButton
168
+ //
169
+ this.otherButton.Location = new System.Drawing.Point(538, 54);
170
+ this.otherButton.Name = "otherButton";
171
+ this.otherButton.Size = new System.Drawing.Size(75, 23);
172
+ this.otherButton.TabIndex = 4;
173
+ this.otherButton.Text = "otherButton";
174
+ this.otherButton.UseVisualStyleBackColor = true;
175
+ //
176
+ // label1
177
+ //
178
+ this.label1.AutoSize = true;
179
+ this.label1.Location = new System.Drawing.Point(3, 10);
180
+ this.label1.Name = "label1";
181
+ this.label1.Size = new System.Drawing.Size(35, 12);
182
+ this.label1.TabIndex = 3;
183
+ this.label1.Text = "label1";
184
+ //
185
+ // Form1
186
+ //
187
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
188
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
189
+ this.ClientSize = new System.Drawing.Size(800, 450);
190
+ this.Controls.Add(this.otherButton);
191
+ this.Controls.Add(this.panel1);
192
+ this.Name = "Form1";
193
+ this.Text = "Form1";
194
+ this.panel1.ResumeLayout(false);
195
+ this.panel1.PerformLayout();
196
+ this.ResumeLayout(false);
197
+
198
+ }
199
+
200
+ #endregion
201
+ private System.Windows.Forms.Label label1;
202
+ private System.Windows.Forms.Button otherButton;
203
+ private System.Windows.Forms.Button button1;
204
+ private System.Windows.Forms.Button button2;
205
+ private System.Windows.Forms.Button button3;
206
+ private System.Windows.Forms.Panel panel1;
207
+ }
208
+ }
209
+ ```
210
+
211
+ Program.cs
212
+ ```C#
213
+ using System;
214
+ using System.Windows.Forms;
215
+
216
+ namespace Questions293390
217
+ {
218
+ static class Program
219
+ {
220
+ [STAThread]
221
+ static void Main()
222
+ {
223
+ Application.EnableVisualStyles();
224
+ Application.SetCompatibleTextRenderingDefault(false);
225
+ Application.Run(Form1.Instance);
226
+ }
227
+ }
228
+ }
229
+ ```