/// <summary> /// 删除与笔迹strokes相交的文本 /// </summary> /// <param name="myGraphicStrokes"></param> public void removeHitTextBoxes(StrokeCollection myGraphicStrokes) { List <MyRichTextBox> myRichTextBoxs = new List <MyRichTextBox>(); foreach (MyRichTextBox myRichTextBox in Sketch.MyRichTextBoxs) { Rect rectMyRichTextBox = new Rect(new Point(myRichTextBox.RichTextBox.Margin.Left, myRichTextBox.RichTextBox.Margin.Top), new Point(myRichTextBox.RichTextBox.Margin.Left + myRichTextBox.RichTextBox.Width, myRichTextBox.RichTextBox.Margin.Top + myRichTextBox.RichTextBox.Height)); if (MathTool.getInstance().isHitRects(myGraphicStrokes.GetBounds(), rectMyRichTextBox) == true) { myRichTextBoxs.Add(myRichTextBox); } } foreach (MyRichTextBox myRichTextBox in myRichTextBoxs) { Command dtc = new DeleteTextCommand(this, myRichTextBox); dtc.execute(); CommandStack.Push(dtc); } }
/// <summary> /// 按下左键的时候 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public override void _presenter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { //创建一个richTextBox _inkCanvas.CaptureMouse(); List <MyRichTextBox> emptyMyRichTextBoxs = new List <MyRichTextBox>(); foreach (MyRichTextBox myRichTextBox in _inkCollector.Sketch.MyRichTextBoxs) { TextRange textRangeOld = new TextRange(myRichTextBox.RichTextBox.Document.ContentStart, myRichTextBox.RichTextBox.Document.ContentEnd); string textRangeStr1 = textRangeOld.Text.Replace(" ", ""); string textRangeStr2 = textRangeStr1.Replace("\r\n", ""); if (textRangeStr2 == "") { emptyMyRichTextBoxs.Add(myRichTextBox); } } foreach (MyRichTextBox myRichTextBox in emptyMyRichTextBoxs) { DeleteTextCommand dtc = new DeleteTextCommand(_inkCollector, myRichTextBox); dtc.execute(); } _richTextBox = new RichTextBox(); _startpoint = e.GetPosition(_inkCanvas); _richTextBox.Margin = new Thickness(_startpoint.Value.X, _startpoint.Value.Y, 0, 0); _richTextBox.Background = new SolidColorBrush(Colors.Transparent); _richTextBox.AcceptsReturn = true; _richTextBox.BorderBrush = new SolidColorBrush(Colors.Blue); _richTextBox.GotFocus += new RoutedEventHandler(_richTextBox_GotFocus); _richTextBox.LostFocus += new RoutedEventHandler(_richTextBox_LostFocus); _richTextBox.HorizontalAlignment = HorizontalAlignment.Left; _richTextBox.VerticalAlignment = VerticalAlignment.Top; TextRange textRange = new TextRange(_richTextBox.Document.ContentStart, _richTextBox.Document.ContentEnd); textRange.ApplyPropertyValue(RichTextBox.FontFamilyProperty, _inkFrame.TextFontFamily); textRange.ApplyPropertyValue(RichTextBox.FontSizeProperty, "60"); //_inkFrame.TextFontSize); textRange.ApplyPropertyValue(RichTextBox.ForegroundProperty, new SolidColorBrush(Colors.Blue)); //_inkFrame.TextFontColor); textRange.ApplyPropertyValue(RichTextBox.FontWeightProperty, _inkFrame.TextFontWeight); textRange.ApplyPropertyValue(RichTextBox.FontStyleProperty, _inkFrame.TextFontStyle); }