teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

見直しキャンペーン中

2023/07/21 09:37

投稿

TN8001
TN8001

スコア10108

answer CHANGED
@@ -1,180 +1,178 @@
1
- 案1 `InkCollector`を`Panel`にでも引っ掛けて自前で制御する
2
- 好きなタイミングで手書き認識できる。
3
-
4
- 案2 `InkEdit`の上側を隠`ReadOnly`にする
5
- バカバカしいが効果的。
6
-
7
- Form1.cs
8
- ```C#
9
- using System;
10
- using System.Windows.Forms;
11
- using Microsoft.Ink;
12
-
13
- namespace Questions252021
14
- {
15
- public partial class Form1 : Form
16
- {
17
- private InkCollector inkCollector;
18
-
19
- public Form1()
20
- {
21
- InitializeComponent();
22
-
23
- inkCollector = new InkCollector(panel1);
24
- inkCollector.CollectionMode = CollectionMode.InkOnly;
25
- inkCollector.Enabled = true;
26
- inkCollector.Stroke += InkCollector_Stroke;
27
- }
28
-
29
- private void InkCollector_Stroke(object sender, InkCollectorStrokeEventArgs e)
30
- {
31
- // なにか描かれたらタイマー再スタート
32
- timer1.Stop();
33
- timer1.Start();
34
- }
35
-
36
- private void Timer1_Tick(object sender, EventArgs e)
37
- {
38
- timer1.Stop();
39
-
40
- // TextBoxに文字を挿入
41
- textBox1.Paste(inkCollector.Ink.Strokes.ToString());
42
- // 手書きのクリア
43
- inkCollector.Ink.DeleteStrokes(inkCollector.Ink.Strokes);
44
- // パネル再描画(クリア)
45
- panel1.Refresh();
46
- }
47
-
48
- private void InkEdit1_TextChanged(object sender, EventArgs e)
49
- {
50
- // TextBoxに文字を挿入
51
- textBox2.Paste(inkEdit1.Text);
52
- // 手書きのクリア
53
- inkEdit1.Text = "";
54
- }
55
- }
56
- }
57
- ```
58
- Form1.Designer.cs
59
- ```C#
60
- namespace Questions252021
61
- {
62
- partial class Form1
63
- {
64
- /// <summary>
65
- /// 必要なデザイナー変数です。
66
- /// </summary>
67
- private System.ComponentModel.IContainer components = null;
68
-
69
- /// <summary>
70
- /// 使用中のリソースをすべてクリーンアップします。
71
- /// </summary>
72
- /// <param name="disposing">マネージド リソースを破棄する場合は true を指定し、その他の場合は false を指定します。</param>
73
- protected override void Dispose(bool disposing)
74
- {
75
- if(disposing && (components != null))
76
- {
77
- components.Dispose();
78
- }
79
- base.Dispose(disposing);
80
- }
81
-
82
- #region Windows フォーム デザイナーで生成されたコード
83
-
84
- /// <summary>
85
- /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
86
- /// コード エディターで変更しないでください。
87
- /// </summary>
88
- private void InitializeComponent()
89
- {
90
- this.components = new System.ComponentModel.Container();
91
- this.inkEdit1 = new Microsoft.Ink.InkEdit();
92
- this.panel1 = new System.Windows.Forms.Panel();
93
- this.textBox1 = new System.Windows.Forms.TextBox();
94
- this.textBox2 = new System.Windows.Forms.TextBox();
95
- this.panel2 = new System.Windows.Forms.Panel();
96
- this.timer1 = new System.Windows.Forms.Timer(this.components);
97
- this.panel2.SuspendLayout();
98
- this.SuspendLayout();
99
- //
100
- // inkEdit1
101
- //
102
- this.inkEdit1.BackColor = System.Drawing.SystemColors.Window;
103
- this.inkEdit1.BorderStyle = System.Windows.Forms.BorderStyle.None;
104
- this.inkEdit1.Cursor = System.Windows.Forms.Cursors.Default;
105
- this.inkEdit1.InkMode = Microsoft.Ink.InkMode.Ink;
106
- this.inkEdit1.Location = new System.Drawing.Point(0, -30);
107
- this.inkEdit1.Name = "inkEdit1";
108
- this.inkEdit1.ReadOnly = true;
109
- this.inkEdit1.Size = new System.Drawing.Size(400, 130);
110
- this.inkEdit1.TabIndex = 0;
111
- this.inkEdit1.Text = "";
112
- this.inkEdit1.UseMouseForInput = true;
113
- this.inkEdit1.TextChanged += new System.EventHandler(this.InkEdit1_TextChanged);
114
- //
115
- // panel1
116
- //
117
- this.panel1.BackColor = System.Drawing.SystemColors.Window;
118
- this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
119
- this.panel1.Location = new System.Drawing.Point(12, 38);
120
- this.panel1.Name = "panel1";
121
- this.panel1.Size = new System.Drawing.Size(400, 100);
122
- this.panel1.TabIndex = 4;
123
- //
124
- // textBox1
125
- //
126
- this.textBox1.Location = new System.Drawing.Point(13, 13);
127
- this.textBox1.Name = "textBox1";
128
- this.textBox1.Size = new System.Drawing.Size(266, 19);
129
- this.textBox1.TabIndex = 5;
130
- //
131
- // textBox2
132
- //
133
- this.textBox2.Location = new System.Drawing.Point(14, 183);
134
- this.textBox2.Name = "textBox2";
135
- this.textBox2.Size = new System.Drawing.Size(266, 19);
136
- this.textBox2.TabIndex = 6;
137
- //
138
- // panel2
139
- //
140
- this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
141
- this.panel2.Controls.Add(this.inkEdit1);
142
- this.panel2.Location = new System.Drawing.Point(12, 208);
143
- this.panel2.Name = "panel2";
144
- this.panel2.Size = new System.Drawing.Size(400, 100);
145
- this.panel2.TabIndex = 7;
146
- //
147
- // timer1
148
- //
149
- this.timer1.Interval = 2000;
150
- this.timer1.Tick += new System.EventHandler(this.Timer1_Tick);
151
- //
152
- // Form1
153
- //
154
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
155
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
156
- this.ClientSize = new System.Drawing.Size(422, 320);
157
- this.Controls.Add(this.panel2);
158
- this.Controls.Add(this.textBox2);
159
- this.Controls.Add(this.textBox1);
160
- this.Controls.Add(this.panel1);
161
- this.Name = "Form1";
162
- this.Text = "Form1";
163
- this.panel2.ResumeLayout(false);
164
- this.ResumeLayout(false);
165
- this.PerformLayout();
166
-
167
- }
168
-
169
- #endregion
170
-
171
- private Microsoft.Ink.InkEdit inkEdit1;
172
- private System.Windows.Forms.Panel panel1;
173
- private System.Windows.Forms.TextBox textBox1;
174
- private System.Windows.Forms.TextBox textBox2;
175
- private System.Windows.Forms.Panel panel2;
176
- private System.Windows.Forms.Timer timer1;
177
- }
178
- }
179
- ```
1
+ * 案1 `InkCollector`を`Panel`にでも引っ掛けて自前で制御
2
+ 好きなタイミングで手書き認識できる。
3
+ * 案2 `InkEdit`の上側を隠し`ReadOnly`に
4
+ バカバカいが効果的。
5
+
6
+ ```cs:Form1.cs
7
+ using System;
8
+ using System.Windows.Forms;
9
+ using Microsoft.Ink;
10
+
11
+ namespace Questions252021
12
+ {
13
+ public partial class Form1 : Form
14
+ {
15
+ private InkCollector inkCollector;
16
+
17
+ public Form1()
18
+ {
19
+ InitializeComponent();
20
+
21
+ inkCollector = new InkCollector(panel1);
22
+ inkCollector.CollectionMode = CollectionMode.InkOnly;
23
+ inkCollector.Enabled = true;
24
+ inkCollector.Stroke += InkCollector_Stroke;
25
+ }
26
+
27
+ private void InkCollector_Stroke(object sender, InkCollectorStrokeEventArgs e)
28
+ {
29
+ // なにか描かれたらタイマー再スタート
30
+ timer1.Stop();
31
+ timer1.Start();
32
+ }
33
+
34
+ private void Timer1_Tick(object sender, EventArgs e)
35
+ {
36
+ timer1.Stop();
37
+
38
+ // TextBoxに文字を挿入
39
+ textBox1.Paste(inkCollector.Ink.Strokes.ToString());
40
+ // 手書きのクリア
41
+ inkCollector.Ink.DeleteStrokes(inkCollector.Ink.Strokes);
42
+ // パネル再描画(クリア
43
+ panel1.Refresh();
44
+ }
45
+
46
+ private void InkEdit1_TextChanged(object sender, EventArgs e)
47
+ {
48
+ // TextBoxに文字を挿入
49
+ textBox2.Paste(inkEdit1.Text);
50
+ // 手書きのクリア
51
+ inkEdit1.Text = "";
52
+ }
53
+ }
54
+ }
55
+ ```
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);
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();
164
+
165
+ }
166
+
167
+ #endregion
168
+
169
+ private Microsoft.Ink.InkEdit inkEdit1;
170
+ private System.Windows.Forms.Panel panel1;
171
+ private System.Windows.Forms.TextBox textBox1;
172
+ private System.Windows.Forms.TextBox textBox2;
173
+ private System.Windows.Forms.Panel panel2;
174
+ private System.Windows.Forms.Timer timer1;
175
+ }
176
+ }
177
+ ```
180
178
  雑なので何か穴がありそう^^;