1.代碼頁須要在鍵盤按下事件中對輸入文字進行篩選,代碼以下:設計
private void tbxGoToPage_PreviewKeyDown(object sender, KeyEventArgs e) { Console.WriteLine("key_value={0}", e.Key); if ((e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9) || (e.Key >= Key.D0 && e.Key <= Key.D9) || e.Key == Key.Back || e.Key == Key.Left || e.Key == Key.Right) { if (e.KeyboardDevice.Modifiers != ModifierKeys.None) { e.Handled = true; } } else { e.Handled = true; } }
2.設計界面頁須要增長PreviewKeyDown事件,屏蔽輸入法,設置鼠標右鍵菜單爲空繼而屏蔽使用鼠標進行右鍵拷貝功能,代碼以下:blog
<TextBox Name="tbx" Width="50" Height="28" PreviewKeyDown="tbx_PreviewKeyDown" InputMethod.IsInputMethodEnabled="False" ContextMenu="{x:Null}" />