質問編集履歴

1

追記1&2

2020/09/27 07:59

投稿

BeatStar
BeatStar

スコア4958

test CHANGED
File without changes
test CHANGED
@@ -81,3 +81,335 @@
81
81
  開発環境: 無し. csc で直接
82
82
 
83
83
  .NET Framework: (できれば) 2.0
84
+
85
+
86
+
87
+ ----------------------------
88
+
89
+
90
+
91
+ [追記1]
92
+
93
+
94
+
95
+
96
+
97
+ 確かに見落としてました…。
98
+
99
+ ですが私のやり方が悪いのか、やはり失敗します。
100
+
101
+
102
+
103
+ まず、
104
+
105
+
106
+
107
+ ```C#
108
+
109
+ using System;
110
+
111
+ using System.Drawing;
112
+
113
+ using System.Windows.Forms;
114
+
115
+ using System.IO;
116
+
117
+ using System.Reflection;
118
+
119
+
120
+
121
+
122
+
123
+ namespace Sample{
124
+
125
+ class Prog{
126
+
127
+ [STAThread]
128
+
129
+ static void Main(){
130
+
131
+ Form1 form1 = new Form1();
132
+
133
+ Application.Run( form1 );
134
+
135
+ }
136
+
137
+ }
138
+
139
+
140
+
141
+ class Form1 : Form{
142
+
143
+ private WebBrowser webBrowser1;
144
+
145
+ private ToolStrip toolStrip1;
146
+
147
+ private ToolStripButton toolStripButton1;
148
+
149
+ private ToolStripButton toolStripButton2;
150
+
151
+ private ToolStripButton toolStripButton3;
152
+
153
+
154
+
155
+ public Form1(){
156
+
157
+
158
+
159
+ this.SuspendLayout();
160
+
161
+
162
+
163
+ this.toolStrip1 = new ToolStrip();
164
+
165
+
166
+
167
+ // ツールバーのレイアウトを一時的停止
168
+
169
+ this.toolStrip1.SuspendLayout();
170
+
171
+
172
+
173
+ // ツールバーに追加するコントロールの生成
174
+
175
+ this.toolStripButton1 = new ToolStripButton();
176
+
177
+ this.toolStripButton1.Text = "戻る(&P)";
178
+
179
+ //this.toolStripButton1.Image = Image.FromFile(@"image1.jpg");
180
+
181
+ //this.toolStripButton1.DisplayStyle = ToolStripItemDisplayStyle.Image;
182
+
183
+
184
+
185
+ this.toolStripButton2 = new ToolStripButton();
186
+
187
+ this.toolStripButton2.Text = "ホーム(&M)";
188
+
189
+ //this.toolStripButton2.Image = Image.FromFile(@"image3.jpg");
190
+
191
+ //this.toolStripButton2.DisplayStyle = ToolStripItemDisplayStyle.Image;
192
+
193
+ toolStripButton2.Height = 100;
194
+
195
+
196
+
197
+ this.toolStripButton3 = new ToolStripButton();
198
+
199
+ this.toolStripButton3.Text = "次へ(&N)";
200
+
201
+ //this.toolStripButton3.Image = Image.FromFile(@"image3.jpg");
202
+
203
+ //this.toolStripButton3.DisplayStyle = ToolStripItemDisplayStyle.Image;
204
+
205
+ toolStripButton2.Height = 100;
206
+
207
+
208
+
209
+ // ツールバーに登録
210
+
211
+ this.toolStrip1.Items.Add( this.toolStripButton1 );
212
+
213
+ this.toolStrip1.Items.Add( this.toolStripButton2 );
214
+
215
+ this.toolStrip1.Items.Add( this.toolStripButton3 );
216
+
217
+
218
+
219
+ // ウィンドウにツールバーを登録
220
+
221
+ this.Controls.Add( this.toolStrip1 );
222
+
223
+
224
+
225
+ // ツールバーのレイアウト再開
226
+
227
+ this.toolStrip1.ResumeLayout(false);
228
+
229
+ this.toolStrip1.PerformLayout();
230
+
231
+
232
+
233
+ // WebBrowserコントロールを作成
234
+
235
+ /*
236
+
237
+ webBrowser1 = new WebBrowser();
238
+
239
+ webBrowser1.Dock = DockStyle.Fill;
240
+
241
+ webBrowser1.Name = "webBrowser1"; // コントロールとしてフォーム上に追加
242
+
243
+ this.Controls.Add(webBrowser1); // Webページを表示
244
+
245
+ webBrowser1.Navigate("パス");
246
+
247
+ //webBrowser1.Size = new Size( 500, 500 );
248
+
249
+ //webBrowser1.Location = new Point( 10, 10 );
250
+
251
+ webBrowser1.Navigated += new WebBrowserNavigatedEventHandler( webBrowser1_Navigated );
252
+
253
+ webBrowser1.DocumentTitleChanged += new EventHandler( webBrowser1_DocumentTitleChanged );
254
+
255
+ */
256
+
257
+ this.Size = new Size( 500, 500 );
258
+
259
+
260
+
261
+ var assm = Assembly.GetExecutingAssembly();
262
+
263
+
264
+
265
+ // リソースとして埋め込んだ画像ファイルのストリームを取得
266
+
267
+ using (var stream = assm.GetManifestResourceStream("Sample.abc.bmp")) {
268
+
269
+ // 取得したストリームからImageを作成し、背景に設定する
270
+
271
+ this.BackgroundImage = Image.FromStream(stream);
272
+
273
+ this.BackgroundImageLayout = ImageLayout.Center;
274
+
275
+
276
+
277
+ // 過去のバージョンの.NET Frameworkでは、Imageの作成元のStreamを閉じてしまうと例外がスローされた
278
+
279
+ // こういった場合は、次のように一旦ストリームの内容をMemoryStream等にコピーする必要がある
280
+
281
+
282
+
283
+ var memoryStream = new MemoryStream((int)stream.Length);
284
+
285
+
286
+
287
+ stream.CopyTo(memoryStream);
288
+
289
+
290
+
291
+ this.BackgroundImage = Image.FromStream(memoryStream);
292
+
293
+ this.BackgroundImageLayout = ImageLayout.Center;
294
+
295
+
296
+
297
+ }
298
+
299
+
300
+
301
+
302
+
303
+
304
+
305
+ this.ResumeLayout(false);
306
+
307
+ this.PerformLayout();
308
+
309
+ }
310
+
311
+
312
+
313
+ // Updates the URL in TextBoxAddress upon navigation.
314
+
315
+ private void webBrowser1_Navigated( object sender, WebBrowserNavigatedEventArgs e){
316
+
317
+ //this.Text = webBrowser1.Url.ToString();
318
+
319
+ }
320
+
321
+
322
+
323
+ private void webBrowser1_DocumentTitleChanged( object sender, EventArgs e ){
324
+
325
+ //this.Text = webBrowser1.DocumentTitle;
326
+
327
+ //this.Text = webBrowser1.StatusText;
328
+
329
+ }
330
+
331
+ }
332
+
333
+ }
334
+
335
+ ```
336
+
337
+
338
+
339
+ という風にしておいて、
340
+
341
+
342
+
343
+ makefileに
344
+
345
+
346
+
347
+ ```ここに言語を入力
348
+
349
+ # TargetやCscPath等は変数状態で指定しています
350
+
351
+ $(Target): main.cs
352
+
353
+ $(CscPath)/csc /nologo /resource:.\abc.bmp /target:winexe /out:$(Target) main.cs
354
+
355
+ ```
356
+
357
+
358
+
359
+
360
+
361
+ のようにコンパイルしました。
362
+
363
+
364
+
365
+ 生成時のディレクトリ内にabc.bmpがあるとします。
366
+
367
+
368
+
369
+ これを起動しようとしても(恐らく例外が飛んでいる系だろうけど…)起動すらしません。
370
+
371
+
372
+
373
+ ファイルから読み込んでやるときにファイルが無い時に、同じような現象が起きていることから、
374
+
375
+ 『ファイルが無いから』だと思うのですが、Windows API (C言語上で)のときのようにリソースファイル
376
+
377
+ ( WinAPIだと rcファイルに相当 ) が必要なのではないかと思うのですが…。
378
+
379
+
380
+
381
+ しかし
382
+
383
+ [https://smdn.jp/programming/netfx/embeddedresource/#embedresource_commandline](https://smdn.jp/programming/netfx/embeddedresource/#embedresource_commandline)
384
+
385
+ ではそういう書き方がほとんど無いようなので…
386
+
387
+
388
+
389
+ 適当に書いていいのならいいですが、確実に決まったやり方があるはずなので…。
390
+
391
+
392
+
393
+ VC# をインストールしていないのでチェックすることすら…。
394
+
395
+
396
+
397
+ -----------------------------------------------------------------------------------
398
+
399
+
400
+
401
+ [追記2]
402
+
403
+
404
+
405
+ もうちょっと深く潜ってみました。
406
+
407
+
408
+
409
+ [参考](http://kaitei.net/csforms/)ではちょっとスタイリッシュなアクセス方法ですが、
410
+
411
+ 肝心の(WinAPIでのrcファイルに相当する)リソースファイルの書き方が提示されていません…。
412
+
413
+
414
+
415
+ 概要を見る限り、rcファイルに相当する何かがあるはずなのですが…