It should at least help put you on the right path.Īlso, this does not handle cases where the word is split across lines, but shouldn't be too hard to cater for.
Note: Although the original code worked well, I wrote it a long time ago and have not tested my adaptions for this answer.
Rect endRect = end.GetCharacterRect(LogicalDirection.Forward) ĭrawingContext.DrawRectangle(null, pen, Rect.Union(startRect, endRect)) Rect startRect = start.GetCharacterRect(LogicalDirection.Backward) - 'n' characters inserted here, 'm' characters deleted there). Go to Format > Shape Outline, point to Weight, and then choose a thickness. (TextChangedEventArgs includes a list of changes If you want to change multiple text boxes or shapes, click the first text box or shape, and then press and hold Ctrl while you click the other text boxes or shapes. by considering what actually changed relative to an earlier you could probably save some calculation time on large texts Actually, if you did this in the TextChanged event handler, protected override void OnRender(DrawingContext drawingContext) Override Adorner.OnRender() to draw the box using TextPointer.GetCharacterRect() to get the coordinates. RichTextBox box = (RichTextBox)this.AdornedElement īox.Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)InvalidateVisual) Public RectangleAdorner(RichTextBox textbox) I don't know if it's an issue for the RichTextBox, but getting the character coordinates from a TextBox is only possible if it has been rendered at least once since it's content last changed. All you need to do is call InvalidateVisuals() via the dispatcher using DispatcherPriority.Background to ensure it is rendered after the text box. The adorner should hook the TextChanged event of the RichTextBox. _adorner = new RectangleAdorner(superMagic) ĪdornerLayer layer = AdornerLayer.GetAdornerLayer(superMagic) Ĭreate an Adorner to render the rectangle and add it to the AdornerLayer void HostControl_Loaded(object sender, RoutedEventArgs e) The principal seems to be mostly the same.Īdd an AdornerDecorator containing your RichTextBox but inside a ScrollViewer. Make the changes you want, as shown in Figure 4-13 click OK twice.I have done something similar, only underlining text in a TextBox. The Advanced Layout dialog box appears (see Figure 4-13). The other buttons move the object to align with the left margin, center line, and right margin, respectively. To keep the object right where you placed it on the page, click Other under “Horizontal Alignment.” Choose Behind Text to create a watermark, or choose Square for a neat, businesslike look.
For example, choose Tight if you’d like the text to follow the outlines of an irregularly shaped object. These wrapping controls correspond to those on the Formatting Palette, also shown in Figure 4-12. Choose one of the text-wrap styles by clicking its icon. If you havent yet created your Word document, open Word, click Blank document, and create the document as needed before proceeding.Step 2, Click the Home tab.
This will open the document in Microsoft Word. In any event, the appropriate Format dialog box now appears ( Figure 4-12, top).Ĭlick the Layout tab. Double-click the Word document to which you want to add borders. The wording of the bottommost choice on the Format menu depends on the item you’ve selected. In other words, choose Format → Picture, Format → Object, Format → AutoShape, or Format → Text Box. Click to select the graphic or text box, then choose Format→ whatever, or just double-click the graphic.