wpf 实现一个软键盘,
先发个图:
工作有需要实现一个软键盘,本来想用windows自带的软键盘凑合凑合得了,又觉得那个软键盘太大了,所以自己实现了一个。
说一下实现的思路,其实没什么思路 界面就是都由按钮实现,按照键盘的格式布的局。下面放软键盘控件的代码
前台:
后台:
后来发现,把他放在窗口上 要实现使用的方法还需要改点东西,下面放上窗口的代码
前台:
后台:
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace softkeyboard { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { [DllImport("user32.dll")] public static extern int SetWindowLong(IntPtr hWnd, int nindex, IntPtr dwNewLong); [DllImport("user32.dll", SetLastError = true)] public static extern UInt32 GetWindowLong(IntPtr hWnd, int index); public MainWindow() { InitializeComponent(); this.Loaded += MainWindow_Loaded; } private void MainWindow_Loaded(object sender, RoutedEventArgs e) { WindowInteropHelper windowInteropHelper = new WindowInteropHelper(this); IntPtr intPtr = windowInteropHelper.Handle; int value = -20; SetWindowLong(intPtr, value, (IntPtr)0x8000000); } private void MainWindow_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { base.DragMove(); } private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { this.Close(); } } }
所有的代码都已经写在这里了,就不单独上传代码了。