回答編集履歴
3
見直しキャンペーン中
test
CHANGED
@@ -1,515 +1,258 @@
|
|
1
1
|
> 何かいい方法はありませんでしょうか?
|
2
2
|
|
3
|
-
|
4
|
-
|
5
3
|
できるだけ簡単な方法を考えていたのですが、一応めどが立ったので一案として試してみてください(簡単を最優先したので、とても正攻法とは言えません^^;
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
```
|
5
|
+
```cs
|
10
|
-
|
11
6
|
using System;
|
12
|
-
|
13
7
|
using System.Drawing;
|
14
|
-
|
15
8
|
using System.IO;
|
16
|
-
|
17
9
|
using System.Net;
|
18
|
-
|
19
10
|
using System.Windows.Forms;
|
20
11
|
|
21
|
-
|
22
|
-
|
23
12
|
namespace Questions280412
|
24
|
-
|
25
13
|
{
|
26
|
-
|
27
14
|
public partial class Form1 : Form
|
28
|
-
|
29
15
|
{
|
30
|
-
|
31
16
|
public Form1()
|
32
|
-
|
33
|
-
{
|
17
|
+
{
|
34
|
-
|
35
18
|
InitializeComponent2();
|
36
19
|
|
37
|
-
|
38
|
-
|
39
20
|
try
|
40
|
-
|
41
|
-
{
|
21
|
+
{
|
42
|
-
|
43
22
|
// 保存済みファイルがあれば読み込み
|
44
|
-
|
45
23
|
webBrowser1.DocumentText = File.ReadAllText("Questions280412.html");
|
46
|
-
|
47
|
-
}
|
24
|
+
}
|
48
|
-
|
49
25
|
catch
|
50
|
-
|
51
|
-
{
|
26
|
+
{
|
52
|
-
|
53
27
|
// なければ空文字に(何かは入れないとNullReferenceExceptionが出る)
|
54
|
-
|
55
28
|
webBrowser1.DocumentText = "";
|
56
|
-
|
57
|
-
}
|
29
|
+
}
|
58
|
-
|
59
|
-
|
60
30
|
|
61
31
|
// フォント変更
|
62
|
-
|
63
32
|
webBrowser1.DocumentCompleted += (s, e) => webBrowser1.Document.Body.Style = "font-family:メイリオ;";
|
64
|
-
|
65
|
-
}
|
33
|
+
}
|
66
|
-
|
67
|
-
|
68
34
|
|
69
35
|
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
70
|
-
|
71
|
-
{
|
36
|
+
{
|
72
|
-
|
73
37
|
// 終了時に自動保存
|
74
|
-
|
75
38
|
// 次回起動時のためdivを表示に戻しておく
|
76
|
-
|
77
39
|
foreach(HtmlElement div in webBrowser1.Document.GetElementsByTagName("div"))
|
78
|
-
|
79
|
-
{
|
40
|
+
{
|
80
|
-
|
81
41
|
div.Style = "display:block";
|
82
|
-
|
83
|
-
}
|
42
|
+
}
|
84
|
-
|
85
|
-
|
86
43
|
|
87
44
|
// ファイルが書き込めないと例外
|
88
|
-
|
89
45
|
// webBrowser1.DocumentTextだと INPUT CHECKED が反映されないので注意
|
90
|
-
|
91
46
|
File.WriteAllText("Questions280412.html", webBrowser1.Document.Body.InnerHtml);
|
92
|
-
|
93
|
-
}
|
47
|
+
}
|
94
|
-
|
95
|
-
|
96
48
|
|
97
49
|
private void SelectImageButton_Click(object sender, EventArgs e)
|
98
|
-
|
99
|
-
{
|
50
|
+
{
|
100
|
-
|
101
51
|
using(var dlg = new OpenFileDialog())
|
102
|
-
|
103
|
-
{
|
52
|
+
{
|
104
|
-
|
105
53
|
dlg.Filter = "画像ファイル(*.png;*.jpg;*.gif)|*.png;*.jpg;*.gif|すべてのファイル(*.*)|*.*";
|
106
|
-
|
107
54
|
if(dlg.ShowDialog() == DialogResult.OK)
|
108
|
-
|
109
55
|
{
|
110
|
-
|
111
56
|
fileTextBox.Text = dlg.FileName;
|
112
|
-
|
113
57
|
}
|
114
|
-
|
115
|
-
}
|
58
|
+
}
|
116
|
-
|
117
|
-
}
|
59
|
+
}
|
118
|
-
|
119
|
-
|
120
|
-
|
121
60
|
|
122
61
|
|
123
62
|
// 1投稿分のテンプレート
|
124
|
-
|
125
63
|
private const string template = @"
|
126
|
-
|
127
64
|
<div>
|
128
|
-
|
129
65
|
<h1>{{title}}</h1>
|
130
|
-
|
131
66
|
<img src='{{file}}' />
|
132
|
-
|
133
67
|
<br />
|
134
|
-
|
135
68
|
<pre>{{comment}}</pre>
|
136
|
-
|
137
69
|
<label>
|
138
|
-
|
139
70
|
<input type='checkbox' name='like'>お気に入り
|
140
|
-
|
141
71
|
</label>
|
142
|
-
|
143
72
|
<hr />
|
144
|
-
|
145
73
|
</div>";
|
146
74
|
|
147
|
-
|
148
|
-
|
149
75
|
private void PostButton_Click(object sender, EventArgs e)
|
150
|
-
|
151
|
-
{
|
76
|
+
{
|
152
|
-
|
153
77
|
// HTMLエンコード(< を < に変える処理)
|
154
|
-
|
155
78
|
var title = WebUtility.HtmlEncode(titleTextBox.Text);
|
156
|
-
|
157
79
|
var file = WebUtility.HtmlEncode(fileTextBox.Text);
|
158
|
-
|
159
80
|
var comment = WebUtility.HtmlEncode(commentTextBox.Text);
|
160
81
|
|
161
|
-
|
162
|
-
|
163
82
|
// テンプレートの指定部分と置換
|
164
|
-
|
165
83
|
var html = template.Replace("{{title}}", title)
|
166
|
-
|
167
84
|
.Replace("{{file}}", file)
|
168
|
-
|
169
85
|
.Replace("{{comment}}", comment);
|
170
86
|
|
171
|
-
|
172
|
-
|
173
87
|
//webBrowser1.DocumentText += html; // だとダメ
|
174
|
-
|
175
88
|
webBrowser1.Document.Body.InnerHtml += html; // 投稿追加
|
176
|
-
|
177
89
|
// お気に入り状態で追加されるといろいろ面倒なのでぜんぶに戻す
|
178
|
-
|
179
90
|
allRadioButton.Checked = true;
|
180
|
-
|
181
|
-
}
|
91
|
+
}
|
182
|
-
|
183
|
-
|
184
92
|
|
185
93
|
private void AllRadioButton_CheckedChanged(object sender, EventArgs e)
|
186
|
-
|
187
|
-
{
|
94
|
+
{
|
188
|
-
|
189
95
|
// divタグを全列挙
|
190
|
-
|
191
96
|
foreach(HtmlElement div in webBrowser1.Document.GetElementsByTagName("div"))
|
192
|
-
|
193
|
-
{
|
97
|
+
{
|
194
|
-
|
195
98
|
// divを表示に戻す
|
196
|
-
|
197
99
|
div.Style = "display:block";
|
198
|
-
|
199
|
-
}
|
100
|
+
}
|
200
|
-
|
201
|
-
}
|
101
|
+
}
|
202
|
-
|
203
|
-
|
204
102
|
|
205
103
|
private void LikeRadioButton_CheckedChanged(object sender, EventArgs e)
|
206
|
-
|
207
|
-
{
|
104
|
+
{
|
208
|
-
|
209
105
|
// 全体から name='like' のものを全列挙
|
210
|
-
|
211
106
|
foreach(HtmlElement checkbox in webBrowser1.Document.All.GetElementsByName("like"))
|
212
|
-
|
213
|
-
{
|
107
|
+
{
|
214
|
-
|
215
108
|
// チェックボックスがチェックされていなければ...
|
216
|
-
|
217
109
|
if(checkbox.GetAttribute("checked") == "False")
|
218
|
-
|
219
110
|
{
|
220
|
-
|
221
111
|
// div(チェックボックスの親の親)を非表示にする
|
222
|
-
|
223
112
|
checkbox.Parent.Parent.Style = "display:none";
|
224
|
-
|
225
113
|
}
|
226
|
-
|
227
|
-
}
|
114
|
+
}
|
228
|
-
|
229
|
-
}
|
115
|
+
}
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
116
|
|
235
117
|
|
236
118
|
|
237
119
|
// InitializeComponent()を圧縮
|
238
|
-
|
239
120
|
private void InitializeComponent2()
|
240
|
-
|
241
|
-
{
|
121
|
+
{
|
242
|
-
|
243
122
|
((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
|
244
|
-
|
245
123
|
splitContainer1.Panel1.SuspendLayout();
|
246
|
-
|
247
124
|
splitContainer1.Panel2.SuspendLayout();
|
248
|
-
|
249
125
|
splitContainer1.SuspendLayout();
|
250
|
-
|
251
126
|
SuspendLayout();
|
252
127
|
|
253
|
-
|
254
|
-
|
255
128
|
// splitContainer1
|
256
|
-
|
257
129
|
splitContainer1.Dock = DockStyle.Fill;
|
258
130
|
|
259
|
-
|
260
|
-
|
261
131
|
// splitContainer1.Panel1
|
262
|
-
|
263
132
|
splitContainer1.Panel1.Controls.Add(label3);
|
264
|
-
|
265
133
|
splitContainer1.Panel1.Controls.Add(label2);
|
266
|
-
|
267
134
|
splitContainer1.Panel1.Controls.Add(label1);
|
268
|
-
|
269
135
|
splitContainer1.Panel1.Controls.Add(postButton);
|
270
|
-
|
271
136
|
splitContainer1.Panel1.Controls.Add(selectImageButton);
|
272
|
-
|
273
137
|
splitContainer1.Panel1.Controls.Add(commentTextBox);
|
274
|
-
|
275
138
|
splitContainer1.Panel1.Controls.Add(fileTextBox);
|
276
|
-
|
277
139
|
splitContainer1.Panel1.Controls.Add(titleTextBox);
|
278
140
|
|
279
|
-
|
280
|
-
|
281
141
|
// splitContainer1.Panel2
|
282
|
-
|
283
142
|
splitContainer1.Panel2.Controls.Add(likeRadioButton);
|
284
|
-
|
285
143
|
splitContainer1.Panel2.Controls.Add(allRadioButton);
|
286
|
-
|
287
144
|
splitContainer1.Panel2.Controls.Add(webBrowser1);
|
288
|
-
|
289
145
|
splitContainer1.Size = new Size(800, 450);
|
290
|
-
|
291
146
|
splitContainer1.SplitterDistance = 408;
|
292
147
|
|
293
|
-
|
294
|
-
|
295
148
|
// label3
|
296
|
-
|
297
149
|
label3.AutoSize = true;
|
298
|
-
|
299
150
|
label3.Location = new Point(14, 69);
|
300
|
-
|
301
151
|
label3.Text = "コメント";
|
302
152
|
|
303
|
-
|
304
|
-
|
305
153
|
// label2
|
306
|
-
|
307
154
|
label2.AutoSize = true;
|
308
|
-
|
309
155
|
label2.Location = new Point(12, 44);
|
310
|
-
|
311
156
|
label2.Text = "画像パス";
|
312
157
|
|
313
|
-
|
314
|
-
|
315
158
|
// label1
|
316
|
-
|
317
159
|
label1.AutoSize = true;
|
318
|
-
|
319
160
|
label1.Location = new Point(12, 15);
|
320
|
-
|
321
161
|
label1.Text = "タイトル";
|
322
162
|
|
323
|
-
|
324
|
-
|
325
163
|
// postButton
|
326
|
-
|
327
164
|
postButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
328
|
-
|
329
165
|
postButton.Location = new Point(321, 415);
|
330
|
-
|
331
166
|
postButton.Size = new Size(75, 23);
|
332
|
-
|
333
167
|
postButton.Text = "投稿";
|
334
|
-
|
335
168
|
postButton.UseVisualStyleBackColor = true;
|
336
|
-
|
337
169
|
postButton.Click += PostButton_Click;
|
338
170
|
|
339
|
-
|
340
|
-
|
341
171
|
// selectImageButton
|
342
|
-
|
343
172
|
selectImageButton.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
344
|
-
|
345
173
|
selectImageButton.Location = new Point(299, 37);
|
346
|
-
|
347
174
|
selectImageButton.Size = new Size(97, 23);
|
348
|
-
|
349
175
|
selectImageButton.Text = "画像を選択...";
|
350
|
-
|
351
176
|
selectImageButton.UseVisualStyleBackColor = true;
|
352
|
-
|
353
177
|
selectImageButton.Click += SelectImageButton_Click;
|
354
178
|
|
355
|
-
|
356
|
-
|
357
179
|
// commentTextBox
|
358
|
-
|
359
180
|
commentTextBox.AcceptsReturn = true;
|
360
|
-
|
361
181
|
commentTextBox.AcceptsTab = true;
|
362
|
-
|
363
182
|
commentTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
364
|
-
|
365
183
|
commentTextBox.Location = new Point(66, 66);
|
366
|
-
|
367
184
|
commentTextBox.Multiline = true;
|
368
|
-
|
369
185
|
commentTextBox.Size = new Size(330, 343);
|
370
186
|
|
371
|
-
|
372
|
-
|
373
187
|
// fileTextBox
|
374
|
-
|
375
188
|
fileTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
376
|
-
|
377
189
|
fileTextBox.Location = new Point(66, 41);
|
378
|
-
|
379
190
|
fileTextBox.Size = new Size(227, 19);
|
380
191
|
|
381
|
-
|
382
|
-
|
383
192
|
// titleTextBox
|
384
|
-
|
385
193
|
titleTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
386
|
-
|
387
194
|
titleTextBox.Location = new Point(66, 12);
|
388
|
-
|
389
195
|
titleTextBox.Size = new Size(330, 19);
|
390
196
|
|
391
|
-
|
392
|
-
|
393
197
|
// likeRadioButton
|
394
|
-
|
395
198
|
likeRadioButton.Appearance = Appearance.Button;
|
396
|
-
|
397
199
|
likeRadioButton.AutoSize = true;
|
398
|
-
|
399
200
|
likeRadioButton.Location = new Point(54, 5);
|
400
|
-
|
401
201
|
likeRadioButton.TabStop = true;
|
402
|
-
|
403
202
|
likeRadioButton.Text = "お気に入り";
|
404
|
-
|
405
203
|
likeRadioButton.UseVisualStyleBackColor = true;
|
406
|
-
|
407
204
|
likeRadioButton.CheckedChanged += LikeRadioButton_CheckedChanged;
|
408
205
|
|
409
|
-
|
410
|
-
|
411
206
|
// allRadioButton
|
412
|
-
|
413
207
|
allRadioButton.Appearance = Appearance.Button;
|
414
|
-
|
415
208
|
allRadioButton.AutoSize = true;
|
416
|
-
|
417
209
|
allRadioButton.Checked = true;
|
418
|
-
|
419
210
|
allRadioButton.Location = new Point(3, 5);
|
420
|
-
|
421
211
|
allRadioButton.TabStop = true;
|
422
|
-
|
423
212
|
allRadioButton.Text = "ぜんぶ";
|
424
|
-
|
425
213
|
allRadioButton.UseVisualStyleBackColor = true;
|
426
|
-
|
427
214
|
allRadioButton.CheckedChanged += AllRadioButton_CheckedChanged;
|
428
215
|
|
429
|
-
|
430
|
-
|
431
216
|
// webBrowser1
|
432
|
-
|
433
217
|
webBrowser1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
434
|
-
|
435
218
|
webBrowser1.Location = new Point(3, 33);
|
436
|
-
|
437
219
|
webBrowser1.MinimumSize = new Size(20, 20);
|
438
|
-
|
439
220
|
webBrowser1.Size = new Size(382, 414);
|
440
221
|
|
441
|
-
|
442
|
-
|
443
222
|
// Form1
|
444
|
-
|
445
223
|
AutoScaleDimensions = new SizeF(6F, 12F);
|
446
|
-
|
447
224
|
AutoScaleMode = AutoScaleMode.Font;
|
448
|
-
|
449
225
|
ClientSize = new Size(800, 450);
|
450
|
-
|
451
226
|
Controls.Add(splitContainer1);
|
452
|
-
|
453
227
|
Text = "Form1";
|
454
|
-
|
455
228
|
FormClosing += Form1_FormClosing;
|
456
|
-
|
457
229
|
splitContainer1.Panel1.ResumeLayout(false);
|
458
|
-
|
459
230
|
splitContainer1.Panel1.PerformLayout();
|
460
|
-
|
461
231
|
splitContainer1.Panel2.ResumeLayout(false);
|
462
|
-
|
463
232
|
splitContainer1.Panel2.PerformLayout();
|
464
|
-
|
465
233
|
((System.ComponentModel.ISupportInitialize)(splitContainer1)).EndInit();
|
466
|
-
|
467
234
|
splitContainer1.ResumeLayout(false);
|
468
|
-
|
469
235
|
ResumeLayout(false);
|
470
|
-
|
471
|
-
}
|
236
|
+
}
|
472
|
-
|
473
|
-
|
474
237
|
|
475
238
|
private SplitContainer splitContainer1 = new SplitContainer();
|
476
|
-
|
477
239
|
private WebBrowser webBrowser1 = new WebBrowser();
|
478
|
-
|
479
240
|
private Label label3 = new Label();
|
480
|
-
|
481
241
|
private Label label2 = new Label();
|
482
|
-
|
483
242
|
private Label label1 = new Label();
|
484
|
-
|
485
243
|
private Button postButton = new Button();
|
486
|
-
|
487
244
|
private Button selectImageButton = new Button();
|
488
|
-
|
489
245
|
private TextBox commentTextBox = new TextBox();
|
490
|
-
|
491
246
|
private TextBox fileTextBox = new TextBox();
|
492
|
-
|
493
247
|
private TextBox titleTextBox = new TextBox();
|
494
|
-
|
495
248
|
private RadioButton likeRadioButton = new RadioButton();
|
496
|
-
|
497
249
|
private RadioButton allRadioButton = new RadioButton();
|
498
|
-
|
499
250
|
}
|
500
|
-
|
501
251
|
}
|
502
|
-
|
503
252
|
```
|
504
253
|
|
505
|
-
|
506
|
-
|
507
254
|
![アプリ画像](48751df8700e4a94434cec3a2206f504.png)
|
508
|
-
|
509
255
|
**注意**
|
510
|
-
|
511
256
|
Form1.Designer.csのままだと1万字に収まらないので、しかたなくInitializeComponent2を作成。
|
512
|
-
|
513
257
|
いろいろ気が利かない部分があります(改善の余地を残しています^^;
|
514
|
-
|
515
258
|
大量にアイテムがあると、投稿後のお気に入りへの切り替えが激遅い。
|
2
からでいい
test
CHANGED
@@ -52,7 +52,7 @@
|
|
52
52
|
|
53
53
|
// なければ空文字に(何かは入れないとNullReferenceExceptionが出る)
|
54
54
|
|
55
|
-
webBrowser1.DocumentText = "
|
55
|
+
webBrowser1.DocumentText = "";
|
56
56
|
|
57
57
|
}
|
58
58
|
|
1
画像忘れ
test
CHANGED
@@ -504,6 +504,8 @@
|
|
504
504
|
|
505
505
|
|
506
506
|
|
507
|
+
![アプリ画像](48751df8700e4a94434cec3a2206f504.png)
|
508
|
+
|
507
509
|
**注意**
|
508
510
|
|
509
511
|
Form1.Designer.csのままだと1万字に収まらないので、しかたなくInitializeComponent2を作成。
|