예제 #1
0
        public void BindIt(BPLabel link)
        {
            this.TB_Text.Text = link.Content.ToString().Replace("\n", "@");

            Glo.BindComboBoxFontSize(this.DDL_FrontSize, link.FontSize);
            this.TB_Text.TextWrapping = TextWrapping.Wrap;
            this.Show();
        }
예제 #2
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            e.Handled = true;
            // 获取 textBox 对象的相对于 Canvas 的 x坐标 和 y坐标
            double x = (double)this.GetValue(Canvas.LeftProperty);
            double y = (double)this.GetValue(Canvas.TopProperty);

            // KeyEventArgs.Key - 与事件相关的键盘的按键 [System.Windows.Input.Key枚举]
            switch (e.Key)
            {
            // 按 Up 键后 textBox 对象向 上 移动 1 个像素
            // Up 键所对应的 e.PlatformKeyCode == 38
            // 当获得的 e.Key == Key.Unknown 时,可以使用 e.PlatformKeyCode 来确定用户所按的键
            case Key.Up:
                this.SetValue(Canvas.TopProperty, y - 1);
                break;

            case Key.Down:
                this.SetValue(Canvas.TopProperty, y + 1);
                break;

            case Key.Left:
                this.SetValue(Canvas.LeftProperty, x - 1);
                break;

            case Key.Right:
                this.SetValue(Canvas.LeftProperty, x + 1);
                break;

            case Key.Delete:
                if (this.Name.Contains("_blank_") == false)
                {
                    if (MessageBox.Show("您确定要删除吗?",
                                        "删除提示", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                }
                Canvas c = this.Parent as Canvas;
                c.Children.Remove(this);
                break;

            case Key.C:
                break;

            case Key.V:
                if (Keyboard.Modifiers == ModifierKeys.Control)
                {
                    BPLabel tb = new BPLabel();
                    tb.Cursor = Cursors.Hand;
                    tb.SetValue(Canvas.LeftProperty, (double)this.GetValue(Canvas.LeftProperty) + 15);
                    tb.SetValue(Canvas.TopProperty, (double)this.GetValue(Canvas.TopProperty) + 15);
                    Canvas s1c = this.Parent as Canvas;
                    try
                    {
                        s1c.Children.Add(tb);
                    }
                    catch
                    {
                        s1c.Children.Remove(tb);
                    }
                }
                break;

            default:
                break;
            }
            base.OnKeyDown(e);
        }