回答編集履歴

2

見直しキャンペーン中

2023/07/29 08:08

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -1,335 +1,168 @@
1
1
  > こちらの質問の回答者のように波形や周波数表示するプログラムを実行できるようにしたいです。
2
2
 
3
-
4
-
5
3
  言及されたので解説しますが回答の(質問も)コードは、「コンソールアプリケーション」ではありません。
6
-
7
4
  画像の通りGUIアプリケーションです。
8
-
9
5
  その中でもC#では一番~~古い~~歴史のある「Windows フォーム アプリケーション」という種類のものです。
10
-
11
6
  [Windows Forms - Wikipedia](https://ja.wikipedia.org/wiki/Windows_Forms)
12
7
 
13
-
14
-
15
8
  見分けるポイントは
16
-
17
9
  * `using System.Windows.Forms;`
18
-
19
10
  これがあれば確定
20
-
21
11
  * `public partial class Form1 : Form`
22
-
23
12
  これがあればほぼ確定
24
-
25
13
  * `Form1`や`Form`等の文字が出てくる
26
-
27
14
  9割がたそうだろうと思われる
28
-
29
15
  * GUIだがなんのヒントもなし
30
-
31
16
  まずそうだろうと思っていい(選択肢がそれしかなかった時代に書かれたもののことが多い)
32
17
 
33
-
34
-
35
18
  名前の通りWindows上で動くGUIアプリケーションです。
36
-
37
19
  okuda____さんがWindows環境をお持ちでなければ、動かすことはできません(Monoで動くのかもしれませんが詳しく知りません)
38
20
 
39
-
40
-
41
21
  そのうえで回答コードでは、2つのコードが省略されています。
42
-
43
22
  * `Program.cs`
44
-
45
23
  Visual Studioが自動生成するエントリポイントで通常いじることはない。
46
-
47
24
  * `Form1.Designer.cs`
48
-
49
25
  通常デザイナ画面でマウス操作によりコントロール等を配置するが、それをもとにVisual Studioが自動生成する。
50
-
51
26
  かなり長くなるため画像から判断してもらったほうが早い。
52
27
 
53
-
54
-
55
28
  さらに質問者が前提としている外部ライブラリが必要です(`using OxyPlot;`等から判断可能)
56
-
57
29
  回答当時使用したライブラリはこの3つです。
58
-
59
30
  * [NuGet Gallery | MathNet.Numerics 4.12.0](https://www.nuget.org/packages/MathNet.Numerics/4.12.0)
60
-
61
31
  * [NuGet Gallery | NAudio 1.10.0](https://www.nuget.org/packages/NAudio/1.10.0)
62
-
63
32
  * [NuGet Gallery | OxyPlot.WindowsForms 2.0.0](https://www.nuget.org/packages/OxyPlot.WindowsForms/2.0.0)
64
-
65
-
66
33
 
67
34
  ---
68
35
 
69
-
70
-
71
36
  省略したコードを上げるのはやぶさかではないですが、私はVisual Studio Codeでの実行方法は全く分かりません。
72
-
73
-
74
37
 
75
38
  Visual Studioを入れてもらうのが一番いいと思います(ちょうどVisual Studio 2022も出たとこですし)
76
39
 
77
-
78
-
79
40
  ---
80
41
 
81
-
82
-
83
42
  Visual Studioもあるんですね^^;
84
-
85
43
  NuGetでライブラリを入れたうえで、画像のようにコントロールを配置してください(位置や大きさはあまり関係ないです)
86
-
87
44
  `Label`2つ(`micname`・`label1`)
88
-
89
45
  `Button`1つ(`Click`イベント`recording_Click`)
90
-
91
46
  `PlotView`2つ(`plotView1`・`plotView2`)
92
47
 
93
-
48
+ 念のため
94
-
95
- 念のためForm1.Designer.cs
49
+ ```cs:Form1.Designer.cs
96
-
97
- ```C#
98
-
99
50
  namespace Questions296462
100
-
101
51
  {
102
-
103
52
  partial class Form1
104
-
105
53
  {
54
+ /// <summary>
55
+ /// 必要なデザイナー変数です。
56
+ /// </summary>
57
+ private System.ComponentModel.IContainer components = null;
106
58
 
107
59
  /// <summary>
60
+ /// 使用中のリソースをすべてクリーンアップします。
61
+ /// </summary>
62
+ /// <param name="disposing">マネージド リソースを破棄する場合は true を指定し、その他の場合は false を指定します。</param>
63
+ protected override void Dispose(bool disposing)
64
+ {
65
+ if(disposing && (components != null))
66
+ {
67
+ components.Dispose();
68
+ }
69
+ base.Dispose(disposing);
70
+ }
108
71
 
109
- /// 必要なデザイナー変数す。
72
+ #region Windows フォーム デザイナーで生成されたコード
110
-
111
- /// </summary>
112
-
113
- private System.ComponentModel.IContainer components = null;
114
-
115
-
116
73
 
117
74
  /// <summary>
118
-
75
+ /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
119
- /// 使用中のリソスをすべてクリンアップます
76
+ /// ド エディタで変更ないでください
120
-
121
77
  /// </summary>
122
-
123
- /// <param name="disposing">マネージド リソースを破棄する場合は true を指定し、その他の場合は false を指定します。</param>
124
-
125
- protected override void Dispose(bool disposing)
78
+ private void InitializeComponent()
126
-
127
79
  {
128
-
129
- if(disposing && (components != null))
80
+ this.micname = new System.Windows.Forms.Label();
130
-
81
+ this.plotView1 = new OxyPlot.WindowsForms.PlotView();
82
+ this.plotView2 = new OxyPlot.WindowsForms.PlotView();
131
- {
83
+ this.button1 = new System.Windows.Forms.Button();
132
-
133
- components.Dispose();
84
+ this.label1 = new System.Windows.Forms.Label();
134
-
135
- }
136
-
137
- base.Dispose(disposing);
85
+ this.SuspendLayout();
86
+ //
87
+ // micname
88
+ //
89
+ this.micname.AutoSize = true;
90
+ this.micname.Location = new System.Drawing.Point(12, 9);
91
+ this.micname.Name = "micname";
92
+ this.micname.Size = new System.Drawing.Size(35, 12);
93
+ this.micname.TabIndex = 0;
94
+ this.micname.Text = "label1";
95
+ //
96
+ // plotView1
97
+ //
98
+ this.plotView1.BackColor = System.Drawing.Color.White;
99
+ this.plotView1.Location = new System.Drawing.Point(14, 67);
100
+ this.plotView1.Name = "plotView1";
101
+ this.plotView1.PanCursor = System.Windows.Forms.Cursors.Hand;
102
+ this.plotView1.Size = new System.Drawing.Size(316, 161);
103
+ this.plotView1.TabIndex = 1;
104
+ this.plotView1.Text = "plotView1";
105
+ this.plotView1.ZoomHorizontalCursor = System.Windows.Forms.Cursors.SizeWE;
106
+ this.plotView1.ZoomRectangleCursor = System.Windows.Forms.Cursors.SizeNWSE;
107
+ this.plotView1.ZoomVerticalCursor = System.Windows.Forms.Cursors.SizeNS;
108
+ //
109
+ // plotView2
110
+ //
111
+ this.plotView2.BackColor = System.Drawing.Color.White;
112
+ this.plotView2.Location = new System.Drawing.Point(14, 243);
113
+ this.plotView2.Name = "plotView2";
114
+ this.plotView2.PanCursor = System.Windows.Forms.Cursors.Hand;
115
+ this.plotView2.Size = new System.Drawing.Size(316, 161);
116
+ this.plotView2.TabIndex = 2;
117
+ this.plotView2.Text = "plotView2";
118
+ this.plotView2.ZoomHorizontalCursor = System.Windows.Forms.Cursors.SizeWE;
119
+ this.plotView2.ZoomRectangleCursor = System.Windows.Forms.Cursors.SizeNWSE;
120
+ this.plotView2.ZoomVerticalCursor = System.Windows.Forms.Cursors.SizeNS;
121
+ //
122
+ // button1
123
+ //
124
+ this.button1.Location = new System.Drawing.Point(255, 38);
125
+ this.button1.Name = "button1";
126
+ this.button1.Size = new System.Drawing.Size(75, 23);
127
+ this.button1.TabIndex = 3;
128
+ this.button1.Text = "button1";
129
+ this.button1.UseVisualStyleBackColor = true;
130
+ this.button1.Click += new System.EventHandler(this.recording_Click);
131
+ //
132
+ // label1
133
+ //
134
+ this.label1.AutoSize = true;
135
+ this.label1.Location = new System.Drawing.Point(14, 49);
136
+ this.label1.Name = "label1";
137
+ this.label1.Size = new System.Drawing.Size(35, 12);
138
+ this.label1.TabIndex = 4;
139
+ this.label1.Text = "label1";
140
+ //
141
+ // Form1
142
+ //
143
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
144
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
145
+ this.ClientSize = new System.Drawing.Size(342, 414);
146
+ this.Controls.Add(this.label1);
147
+ this.Controls.Add(this.button1);
148
+ this.Controls.Add(this.plotView2);
149
+ this.Controls.Add(this.plotView1);
150
+ this.Controls.Add(this.micname);
151
+ this.Name = "Form1";
152
+ this.Text = "Form1";
153
+ this.Load += new System.EventHandler(this.Form1_Load);
154
+ this.ResumeLayout(false);
155
+ this.PerformLayout();
138
156
 
139
157
  }
140
158
 
141
-
142
-
143
- #region Windows フォーム デザイナーで生成されたコード
144
-
145
-
146
-
147
- /// <summary>
148
-
149
- /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
150
-
151
- /// コード エディターで変更しないでください。
152
-
153
- /// </summary>
154
-
155
- private void InitializeComponent()
156
-
157
- {
158
-
159
- this.micname = new System.Windows.Forms.Label();
160
-
161
- this.plotView1 = new OxyPlot.WindowsForms.PlotView();
162
-
163
- this.plotView2 = new OxyPlot.WindowsForms.PlotView();
164
-
165
- this.button1 = new System.Windows.Forms.Button();
166
-
167
- this.label1 = new System.Windows.Forms.Label();
168
-
169
- this.SuspendLayout();
170
-
171
- //
172
-
173
- // micname
174
-
175
- //
176
-
177
- this.micname.AutoSize = true;
178
-
179
- this.micname.Location = new System.Drawing.Point(12, 9);
180
-
181
- this.micname.Name = "micname";
182
-
183
- this.micname.Size = new System.Drawing.Size(35, 12);
184
-
185
- this.micname.TabIndex = 0;
186
-
187
- this.micname.Text = "label1";
188
-
189
- //
190
-
191
- // plotView1
192
-
193
- //
194
-
195
- this.plotView1.BackColor = System.Drawing.Color.White;
196
-
197
- this.plotView1.Location = new System.Drawing.Point(14, 67);
198
-
199
- this.plotView1.Name = "plotView1";
200
-
201
- this.plotView1.PanCursor = System.Windows.Forms.Cursors.Hand;
202
-
203
- this.plotView1.Size = new System.Drawing.Size(316, 161);
204
-
205
- this.plotView1.TabIndex = 1;
206
-
207
- this.plotView1.Text = "plotView1";
208
-
209
- this.plotView1.ZoomHorizontalCursor = System.Windows.Forms.Cursors.SizeWE;
210
-
211
- this.plotView1.ZoomRectangleCursor = System.Windows.Forms.Cursors.SizeNWSE;
212
-
213
- this.plotView1.ZoomVerticalCursor = System.Windows.Forms.Cursors.SizeNS;
214
-
215
- //
216
-
217
- // plotView2
218
-
219
- //
220
-
221
- this.plotView2.BackColor = System.Drawing.Color.White;
222
-
223
- this.plotView2.Location = new System.Drawing.Point(14, 243);
224
-
225
- this.plotView2.Name = "plotView2";
226
-
227
- this.plotView2.PanCursor = System.Windows.Forms.Cursors.Hand;
228
-
229
- this.plotView2.Size = new System.Drawing.Size(316, 161);
230
-
231
- this.plotView2.TabIndex = 2;
232
-
233
- this.plotView2.Text = "plotView2";
234
-
235
- this.plotView2.ZoomHorizontalCursor = System.Windows.Forms.Cursors.SizeWE;
236
-
237
- this.plotView2.ZoomRectangleCursor = System.Windows.Forms.Cursors.SizeNWSE;
238
-
239
- this.plotView2.ZoomVerticalCursor = System.Windows.Forms.Cursors.SizeNS;
240
-
241
- //
242
-
243
- // button1
244
-
245
- //
246
-
247
- this.button1.Location = new System.Drawing.Point(255, 38);
248
-
249
- this.button1.Name = "button1";
250
-
251
- this.button1.Size = new System.Drawing.Size(75, 23);
252
-
253
- this.button1.TabIndex = 3;
254
-
255
- this.button1.Text = "button1";
256
-
257
- this.button1.UseVisualStyleBackColor = true;
258
-
259
- this.button1.Click += new System.EventHandler(this.recording_Click);
260
-
261
- //
262
-
263
- // label1
264
-
265
- //
266
-
267
- this.label1.AutoSize = true;
268
-
269
- this.label1.Location = new System.Drawing.Point(14, 49);
270
-
271
- this.label1.Name = "label1";
272
-
273
- this.label1.Size = new System.Drawing.Size(35, 12);
274
-
275
- this.label1.TabIndex = 4;
276
-
277
- this.label1.Text = "label1";
278
-
279
- //
280
-
281
- // Form1
282
-
283
- //
284
-
285
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
286
-
287
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
288
-
289
- this.ClientSize = new System.Drawing.Size(342, 414);
290
-
291
- this.Controls.Add(this.label1);
292
-
293
- this.Controls.Add(this.button1);
294
-
295
- this.Controls.Add(this.plotView2);
296
-
297
- this.Controls.Add(this.plotView1);
298
-
299
- this.Controls.Add(this.micname);
300
-
301
- this.Name = "Form1";
302
-
303
- this.Text = "Form1";
304
-
305
- this.Load += new System.EventHandler(this.Form1_Load);
306
-
307
- this.ResumeLayout(false);
308
-
309
- this.PerformLayout();
310
-
311
-
312
-
313
- }
314
-
315
-
316
-
317
159
  #endregion
318
160
 
319
-
320
-
321
161
  private System.Windows.Forms.Label micname;
322
-
323
162
  private OxyPlot.WindowsForms.PlotView plotView1;
324
-
325
163
  private OxyPlot.WindowsForms.PlotView plotView2;
326
-
327
164
  private System.Windows.Forms.Button button1;
328
-
329
165
  private System.Windows.Forms.Label label1;
330
-
331
166
  }
332
-
333
167
  }
334
-
335
168
  ```

1

Form1.Designer.cs 追記

2021/11/10 08:47

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -73,3 +73,263 @@
73
73
 
74
74
 
75
75
  Visual Studioを入れてもらうのが一番いいと思います(ちょうどVisual Studio 2022も出たとこですし)
76
+
77
+
78
+
79
+ ---
80
+
81
+
82
+
83
+ Visual Studioもあるんですね^^;
84
+
85
+ NuGetでライブラリを入れたうえで、画像のようにコントロールを配置してください(位置や大きさはあまり関係ないです)
86
+
87
+ `Label`2つ(`micname`・`label1`)
88
+
89
+ `Button`1つ(`Click`イベント`recording_Click`)
90
+
91
+ `PlotView`2つ(`plotView1`・`plotView2`)
92
+
93
+
94
+
95
+ 念のためForm1.Designer.cs
96
+
97
+ ```C#
98
+
99
+ namespace Questions296462
100
+
101
+ {
102
+
103
+ partial class Form1
104
+
105
+ {
106
+
107
+ /// <summary>
108
+
109
+ /// 必要なデザイナー変数です。
110
+
111
+ /// </summary>
112
+
113
+ private System.ComponentModel.IContainer components = null;
114
+
115
+
116
+
117
+ /// <summary>
118
+
119
+ /// 使用中のリソースをすべてクリーンアップします。
120
+
121
+ /// </summary>
122
+
123
+ /// <param name="disposing">マネージド リソースを破棄する場合は true を指定し、その他の場合は false を指定します。</param>
124
+
125
+ protected override void Dispose(bool disposing)
126
+
127
+ {
128
+
129
+ if(disposing && (components != null))
130
+
131
+ {
132
+
133
+ components.Dispose();
134
+
135
+ }
136
+
137
+ base.Dispose(disposing);
138
+
139
+ }
140
+
141
+
142
+
143
+ #region Windows フォーム デザイナーで生成されたコード
144
+
145
+
146
+
147
+ /// <summary>
148
+
149
+ /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
150
+
151
+ /// コード エディターで変更しないでください。
152
+
153
+ /// </summary>
154
+
155
+ private void InitializeComponent()
156
+
157
+ {
158
+
159
+ this.micname = new System.Windows.Forms.Label();
160
+
161
+ this.plotView1 = new OxyPlot.WindowsForms.PlotView();
162
+
163
+ this.plotView2 = new OxyPlot.WindowsForms.PlotView();
164
+
165
+ this.button1 = new System.Windows.Forms.Button();
166
+
167
+ this.label1 = new System.Windows.Forms.Label();
168
+
169
+ this.SuspendLayout();
170
+
171
+ //
172
+
173
+ // micname
174
+
175
+ //
176
+
177
+ this.micname.AutoSize = true;
178
+
179
+ this.micname.Location = new System.Drawing.Point(12, 9);
180
+
181
+ this.micname.Name = "micname";
182
+
183
+ this.micname.Size = new System.Drawing.Size(35, 12);
184
+
185
+ this.micname.TabIndex = 0;
186
+
187
+ this.micname.Text = "label1";
188
+
189
+ //
190
+
191
+ // plotView1
192
+
193
+ //
194
+
195
+ this.plotView1.BackColor = System.Drawing.Color.White;
196
+
197
+ this.plotView1.Location = new System.Drawing.Point(14, 67);
198
+
199
+ this.plotView1.Name = "plotView1";
200
+
201
+ this.plotView1.PanCursor = System.Windows.Forms.Cursors.Hand;
202
+
203
+ this.plotView1.Size = new System.Drawing.Size(316, 161);
204
+
205
+ this.plotView1.TabIndex = 1;
206
+
207
+ this.plotView1.Text = "plotView1";
208
+
209
+ this.plotView1.ZoomHorizontalCursor = System.Windows.Forms.Cursors.SizeWE;
210
+
211
+ this.plotView1.ZoomRectangleCursor = System.Windows.Forms.Cursors.SizeNWSE;
212
+
213
+ this.plotView1.ZoomVerticalCursor = System.Windows.Forms.Cursors.SizeNS;
214
+
215
+ //
216
+
217
+ // plotView2
218
+
219
+ //
220
+
221
+ this.plotView2.BackColor = System.Drawing.Color.White;
222
+
223
+ this.plotView2.Location = new System.Drawing.Point(14, 243);
224
+
225
+ this.plotView2.Name = "plotView2";
226
+
227
+ this.plotView2.PanCursor = System.Windows.Forms.Cursors.Hand;
228
+
229
+ this.plotView2.Size = new System.Drawing.Size(316, 161);
230
+
231
+ this.plotView2.TabIndex = 2;
232
+
233
+ this.plotView2.Text = "plotView2";
234
+
235
+ this.plotView2.ZoomHorizontalCursor = System.Windows.Forms.Cursors.SizeWE;
236
+
237
+ this.plotView2.ZoomRectangleCursor = System.Windows.Forms.Cursors.SizeNWSE;
238
+
239
+ this.plotView2.ZoomVerticalCursor = System.Windows.Forms.Cursors.SizeNS;
240
+
241
+ //
242
+
243
+ // button1
244
+
245
+ //
246
+
247
+ this.button1.Location = new System.Drawing.Point(255, 38);
248
+
249
+ this.button1.Name = "button1";
250
+
251
+ this.button1.Size = new System.Drawing.Size(75, 23);
252
+
253
+ this.button1.TabIndex = 3;
254
+
255
+ this.button1.Text = "button1";
256
+
257
+ this.button1.UseVisualStyleBackColor = true;
258
+
259
+ this.button1.Click += new System.EventHandler(this.recording_Click);
260
+
261
+ //
262
+
263
+ // label1
264
+
265
+ //
266
+
267
+ this.label1.AutoSize = true;
268
+
269
+ this.label1.Location = new System.Drawing.Point(14, 49);
270
+
271
+ this.label1.Name = "label1";
272
+
273
+ this.label1.Size = new System.Drawing.Size(35, 12);
274
+
275
+ this.label1.TabIndex = 4;
276
+
277
+ this.label1.Text = "label1";
278
+
279
+ //
280
+
281
+ // Form1
282
+
283
+ //
284
+
285
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
286
+
287
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
288
+
289
+ this.ClientSize = new System.Drawing.Size(342, 414);
290
+
291
+ this.Controls.Add(this.label1);
292
+
293
+ this.Controls.Add(this.button1);
294
+
295
+ this.Controls.Add(this.plotView2);
296
+
297
+ this.Controls.Add(this.plotView1);
298
+
299
+ this.Controls.Add(this.micname);
300
+
301
+ this.Name = "Form1";
302
+
303
+ this.Text = "Form1";
304
+
305
+ this.Load += new System.EventHandler(this.Form1_Load);
306
+
307
+ this.ResumeLayout(false);
308
+
309
+ this.PerformLayout();
310
+
311
+
312
+
313
+ }
314
+
315
+
316
+
317
+ #endregion
318
+
319
+
320
+
321
+ private System.Windows.Forms.Label micname;
322
+
323
+ private OxyPlot.WindowsForms.PlotView plotView1;
324
+
325
+ private OxyPlot.WindowsForms.PlotView plotView2;
326
+
327
+ private System.Windows.Forms.Button button1;
328
+
329
+ private System.Windows.Forms.Label label1;
330
+
331
+ }
332
+
333
+ }
334
+
335
+ ```