回答編集履歴

4

修正

2017/05/15 15:25

投稿

退会済みユーザー
test CHANGED
@@ -92,7 +92,7 @@
92
92
 
93
93
  WPFで考えました。バックスペースとカンマを許容します。
94
94
 
95
- keypressの場合の使える方法です。
95
+ keypressだけで使える方法です。
96
96
 
97
97
 
98
98
 

3

修正

2017/05/15 15:25

投稿

退会済みユーザー
test CHANGED
@@ -92,6 +92,8 @@
92
92
 
93
93
  WPFで考えました。バックスペースとカンマを許容します。
94
94
 
95
+ keypressの場合の使える方法です。
96
+
95
97
 
96
98
 
97
99
  formバージョン

2

修正

2017/05/15 15:25

投稿

退会済みユーザー
test CHANGED
@@ -94,6 +94,64 @@
94
94
 
95
95
 
96
96
 
97
+ formバージョン
98
+
99
+ ```C#
100
+
101
+ using System.Linq;
102
+
103
+ using System.Windows.Forms;
104
+
105
+
106
+
107
+ namespace KeyPressTest2
108
+
109
+ {
110
+
111
+ public partial class Form1 : Form
112
+
113
+ {
114
+
115
+ public Form1()
116
+
117
+ {
118
+
119
+ InitializeComponent();
120
+
121
+ }
122
+
123
+
124
+
125
+ private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
126
+
127
+ {
128
+
129
+ bool cut = false;
130
+
131
+ string check = "0123456789,\b";
132
+
133
+
134
+
135
+ if (check.Contains(e.KeyChar) == false)
136
+
137
+ {
138
+
139
+ cut = true;
140
+
141
+ }
142
+
143
+
144
+
145
+ e.Handled = cut;
146
+
147
+ }
148
+
149
+ }
150
+
151
+ }
152
+
153
+ ```
154
+
97
155
  参考にしたページ
98
156
 
99
157
  [WPF:数値しか受け付けないTextBox](http://d.hatena.ne.jp/nurs/20150427/1430150521)

1

修正

2017/05/15 15:19

投稿

退会済みユーザー
test CHANGED
@@ -91,3 +91,9 @@
91
91
  ```
92
92
 
93
93
  WPFで考えました。バックスペースとカンマを許容します。
94
+
95
+
96
+
97
+ 参考にしたページ
98
+
99
+ [WPF:数値しか受け付けないTextBox](http://d.hatena.ne.jp/nurs/20150427/1430150521)