private void SelectKey(TextBox textBox) { textBox.Background = Brushes.Yellow; var dialog = new KeyInputDialog(); if (dialog.ShowDialog() == true) { AssignKey(textBox, dialog.Key); } textBox.Background = Brushes.White; }
private void Button_Add_Click(object sender, RoutedEventArgs e) { KeyInputDialog dialog = new KeyInputDialog("按键设置", "请按下按键:", -1, ""); dialog.OKButton.Click += (s1, e1) => { if (dialog.KeyCode != -1 && !string.IsNullOrEmpty(dialog.KeyText)) { if (this.boardKeyCodes.ContainsKey(dialog.KeyCode)) { DialogTip warningDialog = new DialogTip("警告", "该按键已经设置。"); warningDialog.ShowDialog(); return; } Size insertBoardSize = new Size(GRID_SIZE * dialog.WidthGridCount + (dialog.WidthGridCount - 1) * GRID_INTERVAL, GRID_SIZE * dialog.HeightGridCount + (dialog.HeightGridCount - 1) * GRID_INTERVAL); Point insertLocation = Utils.ControlLayoutHelper.SearchInsertLocation(this.PreviewCanvas, insertBoardSize, GRID_INTERVAL); if (insertLocation.X == -1 || insertLocation.Y == -1) { DialogTip warningDialog = new DialogTip("警告", "没有合适的位置插入按钮。"); warningDialog.ShowDialog(); return; } //绘制Border Rect borderRect = new Rect(insertLocation.X, insertLocation.Y, insertBoardSize.Width, insertBoardSize.Height); ButtonDefinition bDef = new ButtonDefinition(dialog.KeyCode, dialog.KeyText, borderRect); DraggableBorder draggableBorder = Utils.ControlLayoutHelper.DrawBorderOnCanvas(this, this.PreviewCanvas, bDef); this.InitDraggableBorder(draggableBorder, this.DraggableBorderIndex++); this.canvasBorderList.Add(draggableBorder); this.boardKeyCodes.Add(dialog.KeyCode, dialog.KeyText); } dialog.Close(); }; dialog.ShowDialog(); }