回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,359 +1,178 @@
|
|
1
|
-
案1 `InkCollector`を`Panel`にでも引っ掛けて自前で制御
|
1
|
+
* 案1 `InkCollector`を`Panel`にでも引っ掛けて自前で制御
|
2
|
+
好きなタイミングで手書き認識できる。
|
3
|
+
* 案2 `InkEdit`の上側を隠し`ReadOnly`に
|
4
|
+
バカバカしいが効果的。
|
2
5
|
|
3
|
-
好きなタイミングで手書き認識できる。
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
案2 `InkEdit`の上側を隠し`ReadOnly`にする
|
8
|
-
|
9
|
-
バカバカしいが効果的。
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
Form1.cs
|
6
|
+
```cs:Form1.cs
|
14
|
-
|
15
|
-
```C#
|
16
|
-
|
17
7
|
using System;
|
18
|
-
|
19
8
|
using System.Windows.Forms;
|
20
|
-
|
21
9
|
using Microsoft.Ink;
|
22
10
|
|
23
|
-
|
24
|
-
|
25
11
|
namespace Questions252021
|
26
|
-
|
27
12
|
{
|
28
|
-
|
29
13
|
public partial class Form1 : Form
|
30
|
-
|
31
14
|
{
|
32
|
-
|
33
15
|
private InkCollector inkCollector;
|
34
16
|
|
35
|
-
|
36
|
-
|
37
17
|
public Form1()
|
38
|
-
|
39
18
|
{
|
40
|
-
|
41
19
|
InitializeComponent();
|
42
20
|
|
21
|
+
inkCollector = new InkCollector(panel1);
|
22
|
+
inkCollector.CollectionMode = CollectionMode.InkOnly;
|
23
|
+
inkCollector.Enabled = true;
|
24
|
+
inkCollector.Stroke += InkCollector_Stroke;
|
25
|
+
}
|
43
26
|
|
27
|
+
private void InkCollector_Stroke(object sender, InkCollectorStrokeEventArgs e)
|
28
|
+
{
|
29
|
+
// なにか描かれたらタイマー再スタート
|
30
|
+
timer1.Stop();
|
31
|
+
timer1.Start();
|
32
|
+
}
|
44
33
|
|
45
|
-
|
34
|
+
private void Timer1_Tick(object sender, EventArgs e)
|
35
|
+
{
|
36
|
+
timer1.Stop();
|
46
37
|
|
38
|
+
// TextBoxに文字を挿入
|
39
|
+
textBox1.Paste(inkCollector.Ink.Strokes.ToString());
|
40
|
+
// 手書きのクリア
|
47
|
-
inkCollector.
|
41
|
+
inkCollector.Ink.DeleteStrokes(inkCollector.Ink.Strokes);
|
42
|
+
// パネル再描画(クリア)
|
43
|
+
panel1.Refresh();
|
44
|
+
}
|
48
45
|
|
46
|
+
private void InkEdit1_TextChanged(object sender, EventArgs e)
|
47
|
+
{
|
48
|
+
// TextBoxに文字を挿入
|
49
|
+
textBox2.Paste(inkEdit1.Text);
|
50
|
+
// 手書きのクリア
|
49
|
-
ink
|
51
|
+
inkEdit1.Text = "";
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
```
|
50
56
|
|
57
|
+
```cs:Form1.Designer.cs
|
58
|
+
namespace Questions252021
|
59
|
+
{
|
60
|
+
partial class Form1
|
61
|
+
{
|
62
|
+
/// <summary>
|
63
|
+
/// 必要なデザイナー変数です。
|
64
|
+
/// </summary>
|
65
|
+
private System.ComponentModel.IContainer components = null;
|
66
|
+
|
67
|
+
/// <summary>
|
68
|
+
/// 使用中のリソースをすべてクリーンアップします。
|
69
|
+
/// </summary>
|
70
|
+
/// <param name="disposing">マネージド リソースを破棄する場合は true を指定し、その他の場合は false を指定します。</param>
|
71
|
+
protected override void Dispose(bool disposing)
|
72
|
+
{
|
73
|
+
if(disposing && (components != null))
|
74
|
+
{
|
75
|
+
components.Dispose();
|
76
|
+
}
|
77
|
+
base.Dispose(disposing);
|
78
|
+
}
|
79
|
+
|
80
|
+
#region Windows フォーム デザイナーで生成されたコード
|
81
|
+
|
82
|
+
/// <summary>
|
83
|
+
/// デザイナー サポートに必要なメソッドです。このメソッドの内容を
|
84
|
+
/// コード エディターで変更しないでください。
|
85
|
+
/// </summary>
|
86
|
+
private void InitializeComponent()
|
87
|
+
{
|
88
|
+
this.components = new System.ComponentModel.Container();
|
89
|
+
this.inkEdit1 = new Microsoft.Ink.InkEdit();
|
90
|
+
this.panel1 = new System.Windows.Forms.Panel();
|
91
|
+
this.textBox1 = new System.Windows.Forms.TextBox();
|
92
|
+
this.textBox2 = new System.Windows.Forms.TextBox();
|
93
|
+
this.panel2 = new System.Windows.Forms.Panel();
|
94
|
+
this.timer1 = new System.Windows.Forms.Timer(this.components);
|
95
|
+
this.panel2.SuspendLayout();
|
96
|
+
this.SuspendLayout();
|
97
|
+
//
|
98
|
+
// inkEdit1
|
99
|
+
//
|
100
|
+
this.inkEdit1.BackColor = System.Drawing.SystemColors.Window;
|
101
|
+
this.inkEdit1.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
102
|
+
this.inkEdit1.Cursor = System.Windows.Forms.Cursors.Default;
|
103
|
+
this.inkEdit1.InkMode = Microsoft.Ink.InkMode.Ink;
|
104
|
+
this.inkEdit1.Location = new System.Drawing.Point(0, -30);
|
105
|
+
this.inkEdit1.Name = "inkEdit1";
|
106
|
+
this.inkEdit1.ReadOnly = true;
|
107
|
+
this.inkEdit1.Size = new System.Drawing.Size(400, 130);
|
108
|
+
this.inkEdit1.TabIndex = 0;
|
109
|
+
this.inkEdit1.Text = "";
|
110
|
+
this.inkEdit1.UseMouseForInput = true;
|
111
|
+
this.inkEdit1.TextChanged += new System.EventHandler(this.InkEdit1_TextChanged);
|
112
|
+
//
|
113
|
+
// panel1
|
114
|
+
//
|
115
|
+
this.panel1.BackColor = System.Drawing.SystemColors.Window;
|
116
|
+
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
117
|
+
this.panel1.Location = new System.Drawing.Point(12, 38);
|
118
|
+
this.panel1.Name = "panel1";
|
119
|
+
this.panel1.Size = new System.Drawing.Size(400, 100);
|
120
|
+
this.panel1.TabIndex = 4;
|
121
|
+
//
|
122
|
+
// textBox1
|
123
|
+
//
|
124
|
+
this.textBox1.Location = new System.Drawing.Point(13, 13);
|
51
|
-
i
|
125
|
+
this.textBox1.Name = "textBox1";
|
126
|
+
this.textBox1.Size = new System.Drawing.Size(266, 19);
|
127
|
+
this.textBox1.TabIndex = 5;
|
128
|
+
//
|
129
|
+
// textBox2
|
130
|
+
//
|
131
|
+
this.textBox2.Location = new System.Drawing.Point(14, 183);
|
132
|
+
this.textBox2.Name = "textBox2";
|
133
|
+
this.textBox2.Size = new System.Drawing.Size(266, 19);
|
134
|
+
this.textBox2.TabIndex = 6;
|
135
|
+
//
|
136
|
+
// panel2
|
137
|
+
//
|
138
|
+
this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
139
|
+
this.panel2.Controls.Add(this.inkEdit1);
|
140
|
+
this.panel2.Location = new System.Drawing.Point(12, 208);
|
141
|
+
this.panel2.Name = "panel2";
|
142
|
+
this.panel2.Size = new System.Drawing.Size(400, 100);
|
143
|
+
this.panel2.TabIndex = 7;
|
144
|
+
//
|
145
|
+
// timer1
|
146
|
+
//
|
147
|
+
this.timer1.Interval = 2000;
|
148
|
+
this.timer1.Tick += new System.EventHandler(this.Timer1_Tick);
|
149
|
+
//
|
150
|
+
// Form1
|
151
|
+
//
|
152
|
+
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
153
|
+
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
154
|
+
this.ClientSize = new System.Drawing.Size(422, 320);
|
155
|
+
this.Controls.Add(this.panel2);
|
156
|
+
this.Controls.Add(this.textBox2);
|
157
|
+
this.Controls.Add(this.textBox1);
|
158
|
+
this.Controls.Add(this.panel1);
|
159
|
+
this.Name = "Form1";
|
160
|
+
this.Text = "Form1";
|
161
|
+
this.panel2.ResumeLayout(false);
|
162
|
+
this.ResumeLayout(false);
|
163
|
+
this.PerformLayout();
|
52
164
|
|
53
165
|
}
|
54
166
|
|
55
|
-
|
56
|
-
|
57
|
-
private void InkCollector_Stroke(object sender, InkCollectorStrokeEventArgs e)
|
58
|
-
|
59
|
-
{
|
60
|
-
|
61
|
-
// なにか描かれたらタイマー再スタート
|
62
|
-
|
63
|
-
timer1.Stop();
|
64
|
-
|
65
|
-
timer1.Start();
|
66
|
-
|
67
|
-
}
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
private void Timer1_Tick(object sender, EventArgs e)
|
72
|
-
|
73
|
-
{
|
74
|
-
|
75
|
-
timer1.Stop();
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
// TextBoxに文字を挿入
|
80
|
-
|
81
|
-
textBox1.Paste(inkCollector.Ink.Strokes.ToString());
|
82
|
-
|
83
|
-
// 手書きのクリア
|
84
|
-
|
85
|
-
inkCollector.Ink.DeleteStrokes(inkCollector.Ink.Strokes);
|
86
|
-
|
87
|
-
// パネル再描画(クリア)
|
88
|
-
|
89
|
-
panel1.Refresh();
|
90
|
-
|
91
|
-
}
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
private void InkEdit1_TextChanged(object sender, EventArgs e)
|
96
|
-
|
97
|
-
{
|
98
|
-
|
99
|
-
// TextBoxに文字を挿入
|
100
|
-
|
101
|
-
textBox2.Paste(inkEdit1.Text);
|
102
|
-
|
103
|
-
// 手書きのクリア
|
104
|
-
|
105
|
-
inkEdit1.Text = "";
|
106
|
-
|
107
|
-
}
|
108
|
-
|
109
|
-
}
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
```
|
114
|
-
|
115
|
-
Form1.Designer.cs
|
116
|
-
|
117
|
-
```C#
|
118
|
-
|
119
|
-
namespace Questions252021
|
120
|
-
|
121
|
-
{
|
122
|
-
|
123
|
-
partial class Form1
|
124
|
-
|
125
|
-
{
|
126
|
-
|
127
|
-
/// <summary>
|
128
|
-
|
129
|
-
/// 必要なデザイナー変数です。
|
130
|
-
|
131
|
-
/// </summary>
|
132
|
-
|
133
|
-
private System.ComponentModel.IContainer components = null;
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
/// <summary>
|
138
|
-
|
139
|
-
/// 使用中のリソースをすべてクリーンアップします。
|
140
|
-
|
141
|
-
/// </summary>
|
142
|
-
|
143
|
-
/// <param name="disposing">マネージド リソースを破棄する場合は true を指定し、その他の場合は false を指定します。</param>
|
144
|
-
|
145
|
-
protected override void Dispose(bool disposing)
|
146
|
-
|
147
|
-
{
|
148
|
-
|
149
|
-
if(disposing && (components != null))
|
150
|
-
|
151
|
-
{
|
152
|
-
|
153
|
-
components.Dispose();
|
154
|
-
|
155
|
-
}
|
156
|
-
|
157
|
-
base.Dispose(disposing);
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
#region Windows フォーム デザイナーで生成されたコード
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
/// <summary>
|
168
|
-
|
169
|
-
/// デザイナー サポートに必要なメソッドです。このメソッドの内容を
|
170
|
-
|
171
|
-
/// コード エディターで変更しないでください。
|
172
|
-
|
173
|
-
/// </summary>
|
174
|
-
|
175
|
-
private void InitializeComponent()
|
176
|
-
|
177
|
-
{
|
178
|
-
|
179
|
-
this.components = new System.ComponentModel.Container();
|
180
|
-
|
181
|
-
this.inkEdit1 = new Microsoft.Ink.InkEdit();
|
182
|
-
|
183
|
-
this.panel1 = new System.Windows.Forms.Panel();
|
184
|
-
|
185
|
-
this.textBox1 = new System.Windows.Forms.TextBox();
|
186
|
-
|
187
|
-
this.textBox2 = new System.Windows.Forms.TextBox();
|
188
|
-
|
189
|
-
this.panel2 = new System.Windows.Forms.Panel();
|
190
|
-
|
191
|
-
this.timer1 = new System.Windows.Forms.Timer(this.components);
|
192
|
-
|
193
|
-
this.panel2.SuspendLayout();
|
194
|
-
|
195
|
-
this.SuspendLayout();
|
196
|
-
|
197
|
-
//
|
198
|
-
|
199
|
-
// inkEdit1
|
200
|
-
|
201
|
-
//
|
202
|
-
|
203
|
-
this.inkEdit1.BackColor = System.Drawing.SystemColors.Window;
|
204
|
-
|
205
|
-
this.inkEdit1.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
206
|
-
|
207
|
-
this.inkEdit1.Cursor = System.Windows.Forms.Cursors.Default;
|
208
|
-
|
209
|
-
this.inkEdit1.InkMode = Microsoft.Ink.InkMode.Ink;
|
210
|
-
|
211
|
-
this.inkEdit1.Location = new System.Drawing.Point(0, -30);
|
212
|
-
|
213
|
-
this.inkEdit1.Name = "inkEdit1";
|
214
|
-
|
215
|
-
this.inkEdit1.ReadOnly = true;
|
216
|
-
|
217
|
-
this.inkEdit1.Size = new System.Drawing.Size(400, 130);
|
218
|
-
|
219
|
-
this.inkEdit1.TabIndex = 0;
|
220
|
-
|
221
|
-
this.inkEdit1.Text = "";
|
222
|
-
|
223
|
-
this.inkEdit1.UseMouseForInput = true;
|
224
|
-
|
225
|
-
this.inkEdit1.TextChanged += new System.EventHandler(this.InkEdit1_TextChanged);
|
226
|
-
|
227
|
-
//
|
228
|
-
|
229
|
-
// panel1
|
230
|
-
|
231
|
-
//
|
232
|
-
|
233
|
-
this.panel1.BackColor = System.Drawing.SystemColors.Window;
|
234
|
-
|
235
|
-
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
236
|
-
|
237
|
-
this.panel1.Location = new System.Drawing.Point(12, 38);
|
238
|
-
|
239
|
-
this.panel1.Name = "panel1";
|
240
|
-
|
241
|
-
this.panel1.Size = new System.Drawing.Size(400, 100);
|
242
|
-
|
243
|
-
this.panel1.TabIndex = 4;
|
244
|
-
|
245
|
-
//
|
246
|
-
|
247
|
-
// textBox1
|
248
|
-
|
249
|
-
//
|
250
|
-
|
251
|
-
this.textBox1.Location = new System.Drawing.Point(13, 13);
|
252
|
-
|
253
|
-
this.textBox1.Name = "textBox1";
|
254
|
-
|
255
|
-
this.textBox1.Size = new System.Drawing.Size(266, 19);
|
256
|
-
|
257
|
-
this.textBox1.TabIndex = 5;
|
258
|
-
|
259
|
-
//
|
260
|
-
|
261
|
-
// textBox2
|
262
|
-
|
263
|
-
//
|
264
|
-
|
265
|
-
this.textBox2.Location = new System.Drawing.Point(14, 183);
|
266
|
-
|
267
|
-
this.textBox2.Name = "textBox2";
|
268
|
-
|
269
|
-
this.textBox2.Size = new System.Drawing.Size(266, 19);
|
270
|
-
|
271
|
-
this.textBox2.TabIndex = 6;
|
272
|
-
|
273
|
-
//
|
274
|
-
|
275
|
-
// panel2
|
276
|
-
|
277
|
-
//
|
278
|
-
|
279
|
-
this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
280
|
-
|
281
|
-
this.panel2.Controls.Add(this.inkEdit1);
|
282
|
-
|
283
|
-
this.panel2.Location = new System.Drawing.Point(12, 208);
|
284
|
-
|
285
|
-
this.panel2.Name = "panel2";
|
286
|
-
|
287
|
-
this.panel2.Size = new System.Drawing.Size(400, 100);
|
288
|
-
|
289
|
-
this.panel2.TabIndex = 7;
|
290
|
-
|
291
|
-
//
|
292
|
-
|
293
|
-
// timer1
|
294
|
-
|
295
|
-
//
|
296
|
-
|
297
|
-
this.timer1.Interval = 2000;
|
298
|
-
|
299
|
-
this.timer1.Tick += new System.EventHandler(this.Timer1_Tick);
|
300
|
-
|
301
|
-
//
|
302
|
-
|
303
|
-
// Form1
|
304
|
-
|
305
|
-
//
|
306
|
-
|
307
|
-
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
308
|
-
|
309
|
-
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
310
|
-
|
311
|
-
this.ClientSize = new System.Drawing.Size(422, 320);
|
312
|
-
|
313
|
-
this.Controls.Add(this.panel2);
|
314
|
-
|
315
|
-
this.Controls.Add(this.textBox2);
|
316
|
-
|
317
|
-
this.Controls.Add(this.textBox1);
|
318
|
-
|
319
|
-
this.Controls.Add(this.panel1);
|
320
|
-
|
321
|
-
this.Name = "Form1";
|
322
|
-
|
323
|
-
this.Text = "Form1";
|
324
|
-
|
325
|
-
this.panel2.ResumeLayout(false);
|
326
|
-
|
327
|
-
this.ResumeLayout(false);
|
328
|
-
|
329
|
-
this.PerformLayout();
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
}
|
334
|
-
|
335
|
-
|
336
|
-
|
337
167
|
#endregion
|
338
168
|
|
339
|
-
|
340
|
-
|
341
169
|
private Microsoft.Ink.InkEdit inkEdit1;
|
342
|
-
|
343
170
|
private System.Windows.Forms.Panel panel1;
|
344
|
-
|
345
171
|
private System.Windows.Forms.TextBox textBox1;
|
346
|
-
|
347
172
|
private System.Windows.Forms.TextBox textBox2;
|
348
|
-
|
349
173
|
private System.Windows.Forms.Panel panel2;
|
350
|
-
|
351
174
|
private System.Windows.Forms.Timer timer1;
|
352
|
-
|
353
175
|
}
|
354
|
-
|
355
176
|
}
|
356
|
-
|
357
177
|
```
|
358
|
-
|
359
178
|
雑なので何か穴がありそう^^;
|