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

回答編集履歴

1

見直しキャンペーン中

2023/07/25 13:24

投稿

TN8001
TN8001

スコア10180

answer CHANGED
@@ -1,46 +1,46 @@
1
- `BackSpace`を送るといいながら`Key.Back`がどこにもなくないですか?(まあリンク先が不親切なんですが^^;
1
+ `BackSpace`を送るといいながら`Key.Back`がどこにもなくないですか?(まあリンク先が不親切なんですが^^;
2
-
2
+
3
- このあたりは詳しくありませんが、`Key.Back`を送れば何となく動いてる気はします。
3
+ このあたりは詳しくありませんが、`Key.Back`を送れば何となく動いてる気はします。
4
-
4
+
5
- ```C#
5
+ ```cs
6
- using System.Windows;
6
+ using System.Windows;
7
- using System.Windows.Controls;
7
+ using System.Windows.Controls;
8
- using System.Windows.Input;
8
+ using System.Windows.Input;
9
-
9
+
10
- namespace Questions306813
10
+ namespace Questions306813
11
- {
11
+ {
12
- public partial class MainWindow : Window
12
+ public partial class MainWindow : Window
13
- {
13
+ {
14
- private readonly int MaxLine = 6;
14
+ private readonly int MaxLine = 6;
15
-
15
+
16
- public MainWindow() => InitializeComponent();
16
+ public MainWindow() => InitializeComponent();
17
-
17
+
18
- private void TextBoxKeyDown(object sender, KeyEventArgs e)
18
+ private void TextBoxKeyDown(object sender, KeyEventArgs e)
19
- {
19
+ {
20
- if (TextBox.LineCount == MaxLine)
20
+ if (TextBox.LineCount == MaxLine)
21
- {
21
+ {
22
- if (e.Key == Key.Enter) e.Handled = true;
22
+ if (e.Key == Key.Enter) e.Handled = true;
23
- }
23
+ }
24
- else if (TextBox.LineCount > MaxLine)
24
+ else if (TextBox.LineCount > MaxLine)
25
- {
25
+ {
26
- Send(Key.Back);
26
+ Send(Key.Back);
27
- }
27
+ }
28
- }
28
+ }
29
-
29
+
30
- private void Send(Key key)
30
+ private void Send(Key key)
31
- {
31
+ {
32
- if (Keyboard.PrimaryDevice != null)
32
+ if (Keyboard.PrimaryDevice != null)
33
- {
33
+ {
34
- if (Keyboard.PrimaryDevice.ActiveSource != null)
34
+ if (Keyboard.PrimaryDevice.ActiveSource != null)
35
- {
35
+ {
36
- var e1 = new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, key)
36
+ var e1 = new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, key)
37
- {
37
+ {
38
- RoutedEvent = KeyDownEvent,
38
+ RoutedEvent = KeyDownEvent,
39
- };
39
+ };
40
- InputManager.Current.ProcessInput(e1);
40
+ InputManager.Current.ProcessInput(e1);
41
- }
41
+ }
42
- }
42
+ }
43
- }
43
+ }
44
- }
44
+ }
45
- }
45
+ }
46
46
  ```