質問編集履歴
1
追記1&2
title
CHANGED
File without changes
|
body
CHANGED
@@ -39,4 +39,170 @@
|
|
39
39
|
[情報]
|
40
40
|
言語: C#
|
41
41
|
開発環境: 無し. csc で直接
|
42
|
-
.NET Framework: (できれば) 2.0
|
42
|
+
.NET Framework: (できれば) 2.0
|
43
|
+
|
44
|
+
----------------------------
|
45
|
+
|
46
|
+
[追記1]
|
47
|
+
|
48
|
+
|
49
|
+
確かに見落としてました…。
|
50
|
+
ですが私のやり方が悪いのか、やはり失敗します。
|
51
|
+
|
52
|
+
まず、
|
53
|
+
|
54
|
+
```C#
|
55
|
+
using System;
|
56
|
+
using System.Drawing;
|
57
|
+
using System.Windows.Forms;
|
58
|
+
using System.IO;
|
59
|
+
using System.Reflection;
|
60
|
+
|
61
|
+
|
62
|
+
namespace Sample{
|
63
|
+
class Prog{
|
64
|
+
[STAThread]
|
65
|
+
static void Main(){
|
66
|
+
Form1 form1 = new Form1();
|
67
|
+
Application.Run( form1 );
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
class Form1 : Form{
|
72
|
+
private WebBrowser webBrowser1;
|
73
|
+
private ToolStrip toolStrip1;
|
74
|
+
private ToolStripButton toolStripButton1;
|
75
|
+
private ToolStripButton toolStripButton2;
|
76
|
+
private ToolStripButton toolStripButton3;
|
77
|
+
|
78
|
+
public Form1(){
|
79
|
+
|
80
|
+
this.SuspendLayout();
|
81
|
+
|
82
|
+
this.toolStrip1 = new ToolStrip();
|
83
|
+
|
84
|
+
// ツールバーのレイアウトを一時的停止
|
85
|
+
this.toolStrip1.SuspendLayout();
|
86
|
+
|
87
|
+
// ツールバーに追加するコントロールの生成
|
88
|
+
this.toolStripButton1 = new ToolStripButton();
|
89
|
+
this.toolStripButton1.Text = "戻る(&P)";
|
90
|
+
//this.toolStripButton1.Image = Image.FromFile(@"image1.jpg");
|
91
|
+
//this.toolStripButton1.DisplayStyle = ToolStripItemDisplayStyle.Image;
|
92
|
+
|
93
|
+
this.toolStripButton2 = new ToolStripButton();
|
94
|
+
this.toolStripButton2.Text = "ホーム(&M)";
|
95
|
+
//this.toolStripButton2.Image = Image.FromFile(@"image3.jpg");
|
96
|
+
//this.toolStripButton2.DisplayStyle = ToolStripItemDisplayStyle.Image;
|
97
|
+
toolStripButton2.Height = 100;
|
98
|
+
|
99
|
+
this.toolStripButton3 = new ToolStripButton();
|
100
|
+
this.toolStripButton3.Text = "次へ(&N)";
|
101
|
+
//this.toolStripButton3.Image = Image.FromFile(@"image3.jpg");
|
102
|
+
//this.toolStripButton3.DisplayStyle = ToolStripItemDisplayStyle.Image;
|
103
|
+
toolStripButton2.Height = 100;
|
104
|
+
|
105
|
+
// ツールバーに登録
|
106
|
+
this.toolStrip1.Items.Add( this.toolStripButton1 );
|
107
|
+
this.toolStrip1.Items.Add( this.toolStripButton2 );
|
108
|
+
this.toolStrip1.Items.Add( this.toolStripButton3 );
|
109
|
+
|
110
|
+
// ウィンドウにツールバーを登録
|
111
|
+
this.Controls.Add( this.toolStrip1 );
|
112
|
+
|
113
|
+
// ツールバーのレイアウト再開
|
114
|
+
this.toolStrip1.ResumeLayout(false);
|
115
|
+
this.toolStrip1.PerformLayout();
|
116
|
+
|
117
|
+
// WebBrowserコントロールを作成
|
118
|
+
/*
|
119
|
+
webBrowser1 = new WebBrowser();
|
120
|
+
webBrowser1.Dock = DockStyle.Fill;
|
121
|
+
webBrowser1.Name = "webBrowser1"; // コントロールとしてフォーム上に追加
|
122
|
+
this.Controls.Add(webBrowser1); // Webページを表示
|
123
|
+
webBrowser1.Navigate("パス");
|
124
|
+
//webBrowser1.Size = new Size( 500, 500 );
|
125
|
+
//webBrowser1.Location = new Point( 10, 10 );
|
126
|
+
webBrowser1.Navigated += new WebBrowserNavigatedEventHandler( webBrowser1_Navigated );
|
127
|
+
webBrowser1.DocumentTitleChanged += new EventHandler( webBrowser1_DocumentTitleChanged );
|
128
|
+
*/
|
129
|
+
this.Size = new Size( 500, 500 );
|
130
|
+
|
131
|
+
var assm = Assembly.GetExecutingAssembly();
|
132
|
+
|
133
|
+
// リソースとして埋め込んだ画像ファイルのストリームを取得
|
134
|
+
using (var stream = assm.GetManifestResourceStream("Sample.abc.bmp")) {
|
135
|
+
// 取得したストリームからImageを作成し、背景に設定する
|
136
|
+
this.BackgroundImage = Image.FromStream(stream);
|
137
|
+
this.BackgroundImageLayout = ImageLayout.Center;
|
138
|
+
|
139
|
+
// 過去のバージョンの.NET Frameworkでは、Imageの作成元のStreamを閉じてしまうと例外がスローされた
|
140
|
+
// こういった場合は、次のように一旦ストリームの内容をMemoryStream等にコピーする必要がある
|
141
|
+
|
142
|
+
var memoryStream = new MemoryStream((int)stream.Length);
|
143
|
+
|
144
|
+
stream.CopyTo(memoryStream);
|
145
|
+
|
146
|
+
this.BackgroundImage = Image.FromStream(memoryStream);
|
147
|
+
this.BackgroundImageLayout = ImageLayout.Center;
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
this.ResumeLayout(false);
|
154
|
+
this.PerformLayout();
|
155
|
+
}
|
156
|
+
|
157
|
+
// Updates the URL in TextBoxAddress upon navigation.
|
158
|
+
private void webBrowser1_Navigated( object sender, WebBrowserNavigatedEventArgs e){
|
159
|
+
//this.Text = webBrowser1.Url.ToString();
|
160
|
+
}
|
161
|
+
|
162
|
+
private void webBrowser1_DocumentTitleChanged( object sender, EventArgs e ){
|
163
|
+
//this.Text = webBrowser1.DocumentTitle;
|
164
|
+
//this.Text = webBrowser1.StatusText;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
}
|
168
|
+
```
|
169
|
+
|
170
|
+
という風にしておいて、
|
171
|
+
|
172
|
+
makefileに
|
173
|
+
|
174
|
+
```ここに言語を入力
|
175
|
+
# TargetやCscPath等は変数状態で指定しています
|
176
|
+
$(Target): main.cs
|
177
|
+
$(CscPath)/csc /nologo /resource:.\abc.bmp /target:winexe /out:$(Target) main.cs
|
178
|
+
```
|
179
|
+
|
180
|
+
|
181
|
+
のようにコンパイルしました。
|
182
|
+
|
183
|
+
生成時のディレクトリ内にabc.bmpがあるとします。
|
184
|
+
|
185
|
+
これを起動しようとしても(恐らく例外が飛んでいる系だろうけど…)起動すらしません。
|
186
|
+
|
187
|
+
ファイルから読み込んでやるときにファイルが無い時に、同じような現象が起きていることから、
|
188
|
+
『ファイルが無いから』だと思うのですが、Windows API (C言語上で)のときのようにリソースファイル
|
189
|
+
( WinAPIだと rcファイルに相当 ) が必要なのではないかと思うのですが…。
|
190
|
+
|
191
|
+
しかし
|
192
|
+
[https://smdn.jp/programming/netfx/embeddedresource/#embedresource_commandline](https://smdn.jp/programming/netfx/embeddedresource/#embedresource_commandline)
|
193
|
+
ではそういう書き方がほとんど無いようなので…
|
194
|
+
|
195
|
+
適当に書いていいのならいいですが、確実に決まったやり方があるはずなので…。
|
196
|
+
|
197
|
+
VC# をインストールしていないのでチェックすることすら…。
|
198
|
+
|
199
|
+
-----------------------------------------------------------------------------------
|
200
|
+
|
201
|
+
[追記2]
|
202
|
+
|
203
|
+
もうちょっと深く潜ってみました。
|
204
|
+
|
205
|
+
[参考](http://kaitei.net/csforms/)ではちょっとスタイリッシュなアクセス方法ですが、
|
206
|
+
肝心の(WinAPIでのrcファイルに相当する)リソースファイルの書き方が提示されていません…。
|
207
|
+
|
208
|
+
概要を見る限り、rcファイルに相当する何かがあるはずなのですが…
|