// ------------------------------------------------------------------ // Dump TextRange. // ------------------------------------------------------------------ private static void DumpTextRange(XmlNode writer, TextPointer start, TextPointer end) { if (writer == null) { throw new ArgumentNullException("writer"); } if (start == null) { throw new ArgumentNullException("start"); } if (end == null) { throw new ArgumentNullException("end"); } int cpStart; int cpEnd; TextPointer containerStart = null; TextPointer containerEnd = null; GetContainerRange(start, out containerStart, out containerEnd); cpStart = containerStart.GetOffsetToPosition(start); cpEnd = containerStart.GetOffsetToPosition(end); XmlNode node = PropertyDumpCore.xmldoc.CreateElement("TextRange"); writer.AppendChild(node); AppendAttribute(node, "Start", cpStart); AppendAttribute(node, "Length", cpEnd - cpStart); }
SelectionOffsets GetSelectionOffsetsRTB(RichTextBox richTextBox) { SelectionOffsets selectionOffsets; TextPointer contentStart = richTextBox.Document.ContentStart; // Find the offset for the starting and ending TextPointers. selectionOffsets.Start = contentStart.GetOffsetToPosition(richTextBox.Selection.Start); selectionOffsets.End = contentStart.GetOffsetToPosition(richTextBox.Selection.End); return selectionOffsets; }
private static IEnumerable <string> GetRunsAndInlinecontainersString(FlowDocument doc, TextPointer start = null, TextPointer end = null) { for (TextPointer position = start; position != null && position.CompareTo(end) <= 0; position = position.GetNextContextPosition(LogicalDirection.Forward)) { if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd) { // } else { TextPointer nextPosition = position.GetNextContextPosition(LogicalDirection.Forward); if (position.Parent is Run) { Run run = position.Parent as Run; TextPointer p1 = (position.CompareTo(run.ContentStart) >= 0) ? position : run.ContentStart; TextPointer p2 = (nextPosition.CompareTo(end) <= 0) ? nextPosition : end; int x1 = -position.GetOffsetToPosition(run.ContentStart); int x2 = -p2.GetOffsetToPosition(p1); yield return(run.Text.Substring(x1, x2)); } else if (position.Parent is InlineUIContainer) { InlineUIContainer inline = position.Parent as InlineUIContainer; if (inline.Child is TextBox) { string variable = (inline.Child as TextBox).Tag as String; yield return("[" + variable + "]"); } } } } }
public static void DeleteRunsAndInlinecontainers(this FlowDocument doc, TextPointer start = null, TextPointer end = null) { for (TextPointer position = start; position != null && position.CompareTo(end) <= 0; position = position.GetNextContextPosition(LogicalDirection.Forward)) { if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd) { // } else { TextPointer nextPosition = position.GetNextContextPosition(LogicalDirection.Forward); if (position.Parent is Run) { Run run = position.Parent as Run; TextPointer p1 = (position.CompareTo(run.ContentStart) >= 0) ? position : run.ContentStart; TextPointer p2 = (nextPosition.CompareTo(end) <= 0) ? nextPosition : end; int x2 = -p2.GetOffsetToPosition(p1); p1.DeleteTextInRun(x2); } else if (position.Parent is InlineUIContainer) { InlineUIContainer inline = position.Parent as InlineUIContainer; (inline.Parent as Paragraph).Inlines.Remove(inline); } } } }
private TextRange GetRandomSubRange(TextPointer start, TextPointer end) { TextPointer subStart = start.GetPositionAtOffset(StartIndex % start.GetOffsetToPosition(end)); TextPointer subEnd = start.GetPositionAtOffset(EndIndex % subStart.GetOffsetToPosition(end)); return(new TextRange(subStart, subEnd)); }
// Given a RichTextBox, return the column number of the current caret position public static int Rtb_GetCaretColumnPos(RichTextBox rtb) { TextPointer caretPos = rtb.CaretPosition; TextPointer lineStartPos = caretPos.GetLineStartPosition(0); return(Math.Max(lineStartPos.GetOffsetToPosition(caretPos) - 1, 0)); }
protected void UpdateParagraph() { untouched.Text = CurrentText.Substring(Math.Min(CurrentText.Length, UserText.Length)); PWrapper.Inlines.Clear(); foreach (Run r in Runs) { PWrapper.Inlines.Add(r); } PWrapper.Inlines.Add(Building); PWrapper.Inlines.Add(untouched); TextPointer docStart = CurrentTextTB.Document.ContentStart; TextPointer docEnd = CurrentTextTB.Document.ContentEnd; int trueLength = docStart.GetOffsetToPosition(docEnd); int userStringEndOffset = trueLength - (CurrentText.Length - UserText.Length) - 2; TextPointer tp = CurrentTextTB.Document.ContentStart; tp = tp.GetPositionAtOffset(userStringEndOffset + 10); if (tp == null) { tp = docEnd; } CurrentTextTB.Selection.Select(tp, tp); }
public static int GetPositionInLine(this TextPointer Pointer) { TextPointer tp1 = Pointer.GetLineStartPosition(0); int ox = tp1.GetOffsetToPosition(Pointer); return(ox - 1); }
/// <summary> /// Compute the offset to the caret in terms of actual displayed characters (ignore formatting characters). /// This will be -1 if there is no paragraph that scopes the current position. /// </summary> /// <param name="caretPos">TextPointer to the current caret position</param> /// <returns>Offset to the caret in terms of actual displayed characters</returns> private static int ComputePlaintextOffset(TextPointer caretPos) { int plainTextCaretOffset = -1; Paragraph paragraph = caretPos.Paragraph; if (null != paragraph) { plainTextCaretOffset = paragraph.ContentStart.GetOffsetToPosition(caretPos); // Locate which inline the caret is in foreach (Inline il in paragraph.Inlines) { // Stop if the caret is in the current Inline object if (caretPos.GetOffsetToPosition(il.ContentEnd) >= 0) { // Subtract only 1, for the start of the current inline. plainTextCaretOffset -= 1; break; } // Each new inline object adds 2 to the caret position (1 for the start of the inline // and 1 more for the end of the inline), so compensate by subtracting 2 plainTextCaretOffset -= 2; } } return(plainTextCaretOffset); }
// Token: 0x06006839 RID: 26681 RVA: 0x001D5DD8 File Offset: 0x001D3FD8 internal ReadOnlyCollection <Rect> GetRectanglesCore(ContentElement child, bool isLimitedToTextView) { Invariant.Assert(!this.IsDisposed); List <Rect> list = new List <Rect>(); if (this.IsLayoutDataValid) { TextPointer textPointer = this.FindElementPosition(child, isLimitedToTextView); if (textPointer != null) { int offsetToPosition = this._structuralCache.TextContainer.Start.GetOffsetToPosition(textPointer); int length = 1; if (child is TextElement) { TextPointer position = new TextPointer(((TextElement)child).ElementEnd); length = textPointer.GetOffsetToPosition(position); } list = this._ptsPage.GetRectangles(child, offsetToPosition, length); } } if (this.PageVisual != null && list.Count > 0) { List <Rect> list2 = new List <Rect>(list.Count); GeneralTransform generalTransform = this.PageVisual.Child.TransformToAncestor(this.PageVisual); for (int i = 0; i < list.Count; i++) { list2.Add(generalTransform.TransformBounds(list[i])); } list = list2; } Invariant.Assert(list != null); return(new ReadOnlyCollection <Rect>(list)); }
private void rtbEditor_SelectionChanged(object sender, RoutedEventArgs e) { TextPointer tp1 = rtbEditor.Selection.Start.GetLineStartPosition(0); TextPointer tp2 = rtbEditor.Selection.Start; int column = tp1.GetOffsetToPosition(tp2); int someBigNumber = int.MaxValue; int lineMoved, currentLineNumber; rtbEditor.Selection.Start.GetLineStartPosition(-someBigNumber, out lineMoved); currentLineNumber = -lineMoved; lblPosition.Text = " Line: " + (currentLineNumber + 1).ToString() + " Column: " + column.ToString() + " "; int num = Lines(); if (numOfLine != num) { lineNumChanged(num); numOfLine = num; } }
internal static int GetTextWithLimit(TextPointer thisPointer, LogicalDirection direction, char[] textBuffer, int startIndex, int count, TextPointer limit) { int num2; if (limit == null) { return(thisPointer.GetTextInRun(direction, textBuffer, startIndex, count)); } if ((direction == LogicalDirection.Forward) && (limit.CompareTo(thisPointer) <= 0)) { return(0); } if ((direction == LogicalDirection.Backward) && (limit.CompareTo(thisPointer) >= 0)) { return(0); } if (direction == LogicalDirection.Forward) { num2 = Math.Min(count, thisPointer.GetOffsetToPosition(limit)); } else { num2 = Math.Min(count, limit.GetOffsetToPosition(thisPointer)); } num2 = Math.Min(count, num2); return(thisPointer.GetTextInRun(direction, textBuffer, startIndex, num2)); }
// // Gibt die Spaltennummer der aktuellen Cursorposition zurück private int Spaltennummer() { TextPointer caretPos = RichTextControl.CaretPosition; TextPointer p = RichTextControl.CaretPosition.GetLineStartPosition(0); int currentColumnNumber = Math.Max(p.GetOffsetToPosition(caretPos) - 1, 0); return(currentColumnNumber); }
public static int GetFirtsLineEndPosition(this TextBlock source) { var text = source.Text; TextPointer lineStart = source.ContentStart.GetPositionAtOffset(1, LogicalDirection.Forward); TextPointer lineEnd = lineStart?.GetLineStartPosition(1); return(lineEnd != null?lineStart.GetOffsetToPosition(lineEnd) : text.Length); }
public static int ColumnNumber(this RichTextBox textBox) { TextPointer caretPos = textBox.CaretPosition; TextPointer p = textBox.CaretPosition.GetLineStartPosition(0); int currentColumnNumber = Math.Max(p.GetOffsetToPosition(caretPos) - 1, 0); return(currentColumnNumber + 1); }
private void rchTextBox_SelectionChanged(object sender, EventArgs e) { TextPointer caretPos = rchTextBox.CaretPosition; TextPointer p = rchTextBox.CaretPosition.GetLineStartPosition(0); int currentColumnNumber = Math.Max(p.GetOffsetToPosition(caretPos) - 1, 0); labelCountSymbols.Content = currentColumnNumber.ToString(); }
public static TextPointer InsertTextAt(this FlowDocument doc, string text, TextPointer p) { if (p.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart) { p = p.GetNextContextPosition(LogicalDirection.Backward); } if (p.Parent is FlowDocument) { Run run = new Run(text); Paragraph paragraph = (doc.Blocks.FirstBlock as Paragraph); paragraph.Inlines.InsertBefore(paragraph.Inlines.FirstInline, run); return(run.ContentEnd); } else if (p.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd) { Run run = new Run(text); if (p.Parent is Inline) { Inline inline = p.Parent as Inline; (inline.Parent as Paragraph).Inlines.InsertAfter(inline, run); } else if (p.Parent is Paragraph) { (p.Parent as Paragraph).Inlines.Add(run); } else { throw new Exception("not handled"); } return(run.ContentEnd); } else { if (p.Parent is Run) { Run run = p.Parent as Run; Paragraph paragraph = run.Parent as Paragraph; // break up Run int mid = -p.GetOffsetToPosition(run.ContentStart); run.Text = run.Text.Insert(mid, text); return(run.ContentStart.GetPositionAtOffset(mid + text.Length)); /*Run run1 = new Run(run.Text.Substring(0, mid)); * Run run2 = new Run(run.Text.Substring(mid)); * paragraph.Inlines.InsertBefore(run, run1); * paragraph.Inlines.InsertBefore(run, container); * paragraph.Inlines.InsertBefore(run, run2); * paragraph.Inlines.Remove(run);*/ } else { throw new Exception("not handled"); } } }
// ------------------------------------------------------------------ // Dump line range. // ------------------------------------------------------------------ private static void DumpLineRange(XmlNode writer, TextPointer start, TextPointer end, TextPointer contentEndPosition, TextPointer ellipsesPosition) { if (writer == null) { throw new ArgumentNullException("writer"); } if (start == null) { throw new ArgumentNullException("start"); } if (end == null) { throw new ArgumentNullException("end"); } TextPointer containerStart = null; TextPointer containerEnd = null; GetContainerRange(start, out containerStart, out containerEnd); int cpStart = containerStart.GetOffsetToPosition(start); int cpEnd = containerStart.GetOffsetToPosition(end); int cpContentEnd = containerStart.GetOffsetToPosition(contentEndPosition); XmlNode node = PropertyDumpCore.xmldoc.CreateElement("TextRange"); writer.AppendChild(node); AppendAttribute(node, "Start", cpStart); AppendAttribute(node, "Length", cpEnd - cpStart); if (cpEnd != cpContentEnd) { AppendAttribute(node, "HiddenLength", cpEnd - cpContentEnd); } if (ellipsesPosition != null) { int cpEllipses = containerStart.GetOffsetToPosition(ellipsesPosition); AppendAttribute(node, "EllipsesLength", cpEnd - cpEllipses); } }
public static void DebugAssertIsSingleLine(TextRange range) { // If range.Start and range.End are on the same line the GetLineStartPosition(0) // should return the same value for both range.Start and range.End TextPointer lineStartFromRangeStart = range.Start.GetLineStartPosition(0); TextPointer lineStartFromRangeEnd = range.End.GetLineStartPosition(0); if (lineStartFromRangeStart != null && lineStartFromRangeEnd != null) { // Range must not span more than 1 line Assert.AreEqual(0, lineStartFromRangeStart.GetOffsetToPosition(lineStartFromRangeEnd)); } }
/// <summary> /// Move to the next highlight starting at the <paramref name="caretPosition"/> /// </summary> /// <param name="forward">true for next false for previous</param> /// <param name="caretPosition">caret position</param> /// <returns>the next highlight starting at the <paramref name="caretPosition"/></returns> internal Run MoveAndHighlightNextNextMatch(bool forward, TextPointer caretPosition) { Debug.Assert(caretPosition != null, "a caret position is allways valid"); Debug.Assert(caretPosition.Parent != null && caretPosition.Parent is Run, "a caret PArent is allways a valid Run"); Run caretRun = (Run)caretPosition.Parent; Run currentRun; if (this.currentHighlightedMatch != null) { // restore the curent highlighted background to plain highlighted this.currentHighlightedMatch.Background = ParagraphSearcher.HighlightBrush; } // If the caret is in the end of a highlight we move to the adjacent run // It has to be in the end because if there is a match at the begining of the file // and the caret has not been touched (so it is in the beginning of the file too) // we want to highlight this first match. // Considering the caller allways set the caret to the end of the highlight // The condition below works well for successive searchs // We also need to move to the adjacent run if the caret is at the first run and we // are moving backwards so that a search backwards when the first run is highlighted // and the caret is at the beginning will wrap to the end if ((!forward && IsFirstRun(caretRun)) || ((caretPosition.GetOffsetToPosition(caretRun.ContentEnd) == 0) && ParagraphSearcher.Ishighlighted(caretRun))) { currentRun = ParagraphSearcher.GetNextRun(caretRun, forward); } else { currentRun = caretRun; } currentRun = ParagraphSearcher.GetNextMatch(currentRun, forward); if (currentRun == null) { // if we could not find a next highlight wrap arround currentRun = ParagraphSearcher.GetFirstOrLastRun(caretRun, forward); currentRun = ParagraphSearcher.GetNextMatch(currentRun, forward); } this.currentHighlightedMatch = currentRun; if (this.currentHighlightedMatch != null) { // restore the curent highligthed background to current highlighted this.currentHighlightedMatch.Background = ParagraphSearcher.CurrentHighlightBrush; } return(currentRun); }
private void ChangeFontSize(TextPointer currentPoint, double size, TextPointer endingPoint, bool increase) { // currentPoint can split text, but size is the text's size based on the enclosing tag // find the next position TextPointer next = currentPoint.GetNextContextPosition(LogicalDirection.Forward); //TextPointerContext nextCtx = currentPoint.GetPointerContext(LogicalDirection.Forward); int currentOffset = next.GetOffsetToPosition(endingPoint); TextPointer endOfApply = (currentOffset <= 0) ? endingPoint : next; // apply the style for this portion TextRange range = new TextRange(currentPoint, endOfApply); try { string text = currentPoint.GetTextInRun(LogicalDirection.Forward); double newSize = increase ? GetNextFontSize(size) : GetPreviousFontSize(size); range.ApplyPropertyValue(TextElement.FontSizeProperty, newSize); } catch (Exception) { // ignore return; } if (currentOffset <= 0) { return; // done } // what's next? object element = endOfApply.GetAdjacentElement(LogicalDirection.Forward); TextPointerContext ctx = endOfApply.GetPointerContext(LogicalDirection.Forward); if (element is UIElement) { UIElement uiElement = element as UIElement; } else if (element is TextElement) { TextElement textElement = element as TextElement; size = textElement.FontSize; ChangeFontSize(endOfApply, size, endingPoint, increase); } else { ChangeFontSize(endOfApply, size, endingPoint, increase); } return; // don't know what to do = done }
private void DocumentEditor_SelectionChanged(object sender, RoutedEventArgs e) { TextPointer ls = CaretPosition.GetLineStartPosition(0); TextPointer p = Document.ContentStart.GetLineStartPosition(0); int @int = 1; int int2 = 1; while (true) { if (ls.CompareTo(p) < 1) { break; // TODO: might not be correct. Was : Exit While } int r = 0; p = p.GetLineStartPosition(1, out r); if (r == 0) { break; // TODO: might not be correct. Was : Exit While } @int += 1; } TextPointer ls2 = Document.ContentStart.DocumentEnd.GetLineStartPosition(0); TextPointer p2 = Document.ContentEnd.DocumentStart.GetLineStartPosition(0); while (true) { if (ls2.CompareTo(p2) < 1) { break; // TODO: might not be correct. Was : Exit While } int r = 0; p2 = p2.GetLineStartPosition(1, out r); if (r == 0) { break; // TODO: might not be correct. Was : Exit While } int2 += 1; } SelectedLineNumber = @int; LineCount = int2; TextRange t = new TextRange(Document.ContentStart, Document.ContentEnd); TextPointer caretPos = CaretPosition; TextPointer poi = CaretPosition.GetLineStartPosition(0); int currentColumnNumber = Math.Max(p.GetOffsetToPosition(caretPos) - 1, 0) + 1; int currentColumnCount = currentColumnNumber; currentColumnCount += CaretPosition.GetTextRunLength(System.Windows.Documents.LogicalDirection.Forward); SelectedColumnNumber = currentColumnNumber; ColumnCount = currentColumnCount; }
private void rtbEditor_SelectionChanged(object sender, RoutedEventArgs e) { // toggle buttons object temp = rtbEditor.Selection.GetPropertyValue(Inline.FontWeightProperty); btnBold.IsChecked = (temp != DependencyProperty.UnsetValue) && (temp.Equals(FontWeights.Bold)); temp = rtbEditor.Selection.GetPropertyValue(Inline.FontStyleProperty); btnItalic.IsChecked = (temp != DependencyProperty.UnsetValue) && (temp.Equals(FontStyles.Italic)); temp = rtbEditor.Selection.GetPropertyValue(Inline.TextDecorationsProperty); btnUnderline.IsChecked = (temp != DependencyProperty.UnsetValue) && (temp.Equals(TextDecorations.Underline)); //comboboxs temp = rtbEditor.Selection.GetPropertyValue(Inline.FontFamilyProperty); cmbFontFamily.SelectedItem = temp; temp = rtbEditor.Selection.GetPropertyValue(Inline.FontSizeProperty); cmbFontSize.Text = temp.ToString(); temp = rtbEditor.Selection.GetPropertyValue(Inline.ForegroundProperty); var hexcolor = ((SolidColorBrush)temp).Color.ToString(); SolidColorBrush sol = (SolidColorBrush)temp; saved = 0; string s = new TextRange(rtbEditor.Document.ContentStart, rtbEditor.Document.ContentEnd).Text; char[] delimiters = new char[] { ' ', '\r', '\n' }; string[] pom = s.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); textBox.Text = "Word Count: " + pom.Length.ToString(); TextPointer tp1 = rtbEditor.Selection.Start.GetLineStartPosition(0); TextPointer tp2 = rtbEditor.Selection.Start; int column = tp1.GetOffsetToPosition(tp2) + 1; int someBigNumber = int.MaxValue; int lineMoved, currentLineNumber; rtbEditor.Selection.Start.GetLineStartPosition(-someBigNumber, out lineMoved); currentLineNumber = -lineMoved + 1; lblCursorPosition.Text = "Line: " + currentLineNumber.ToString() + " Column: " + column.ToString(); }
private void CopyTextCommand(object sender, ExecutedRoutedEventArgs ea) { const LogicalDirection forward = LogicalDirection.Forward; TextSelection selection = TbLog.Selection; TextPointer navigator = selection.Start.GetPositionAtOffset(0, forward); TextPointer end = selection.End; var buffer = new StringBuilder(); int offsetToEnd; do { offsetToEnd = navigator.GetOffsetToPosition(end); TextPointerContext context = navigator.GetPointerContext(forward); if (context == TextPointerContext.Text) { string blockText = navigator.GetTextInRun(forward); int croppedLen = Math.Min(offsetToEnd, navigator.GetTextRunLength(forward)); _ = buffer.Append(blockText, 0, croppedLen); } else if ( context == TextPointerContext.ElementEnd && navigator.Parent is Paragraph ) { _ = buffer.AppendLine(); } else if ( navigator.Parent is BlockUIContainer block && block.Child is WorkProgress progress && progress.DataContext is Jp2KrTranslationVM work ) { foreach (Exception e in work.Exceptions) { _ = buffer.AppendLine(e.ToString()); _ = buffer.AppendLine(); } } navigator = navigator.GetNextContextPosition(forward); }while (offsetToEnd > 0); string txt = buffer.ToString(); Clipboard.SetText(txt); ea.Handled = true; }
private void rtbEditor_MouseMove(object sender, MouseEventArgs e) { try { ///* get start pointer */ TextPointer startPtr = rtbEditor.Document.ContentStart; ///* get current caret position */ int start = startPtr.GetOffsetToPosition(rtbEditor.CaretPosition); txtSzukaj.Content = Convert.ToString(start); } catch (Exception ex) { ErrorMessage(ex); } }
public static IEnumerable <string> GetLines(this TextBlock source) { var text = source.Text; int offset = 0; TextPointer lineStart = source.ContentStart.GetPositionAtOffset(1, LogicalDirection.Forward); do { TextPointer lineEnd = lineStart != null?lineStart.GetLineStartPosition(1) : null; int length = lineEnd != null?lineStart.GetOffsetToPosition(lineEnd) : text.Length - offset; yield return(text.Substring(offset, length)); offset += length; lineStart = lineEnd; }while (lineStart != null); }
private void getLines() { TextPointer pos0 = consoleText.Document.ContentStart; TextPointer pos1 = consoleText.CaretPosition; TextPointer posI = consoleText.CaretPosition.GetLineStartPosition(0); TextRange rangeOfText1 = new TextRange(pos0, pos1); TextRange rangeOfTextL = new TextRange(posI, pos1); int length = rangeOfText1.Text.Length; int dif = pos0.GetOffsetToPosition(pos1); int row = (dif - length) / 2; int column = rangeOfTextL.Text.Length; labelRow.Content = "Row -> " + row; labelColumn.Content = "Column -> " + column; }
private void MainTextBox_SelectionChanged(object sender, RoutedEventArgs e) { //тут выводит положение курсора TextPointer tp1 = MainTextBox.Selection.Start.GetLineStartPosition(0); TextPointer tp2 = MainTextBox.Selection.Start; int column = tp1.GetOffsetToPosition(tp2); int someBigNumber = int.MaxValue; int lineMoved, currentLineNumber; MainTextBox.Selection.Start.GetLineStartPosition(-someBigNumber, out lineMoved); currentLineNumber = -lineMoved; lblCursorPosition.Text = "Ряд: " + currentLineNumber.ToString() + " Символ: " + column.ToString(); // тут выполняется применение стиля шрифта будь то жирный, курсив или подчеркнутый object temp = MainTextBox.Selection.GetPropertyValue(Inline.FontWeightProperty); CheckBoldFont.IsChecked = (temp != DependencyProperty.UnsetValue) && (temp.Equals(FontWeights.Bold)); temp = MainTextBox.Selection.GetPropertyValue(Inline.FontStyleProperty); CheckItalicFont.IsChecked = (temp != DependencyProperty.UnsetValue) && (temp.Equals(FontStyles.Italic)); temp = MainTextBox.Selection.GetPropertyValue(Inline.TextDecorationsProperty); CheckUnderlineFont.IsChecked = (temp != DependencyProperty.UnsetValue) && (temp.Equals(TextDecorations.Underline)); //тут положение текста RadioLeft.IsChecked = (temp != DependencyProperty.UnsetValue) && (temp.Equals(TextAlignment.Left)); RadioCenter.IsChecked = (temp != DependencyProperty.UnsetValue) && (temp.Equals(TextAlignment.Center)); RadioRight.IsChecked = (temp != DependencyProperty.UnsetValue) && (temp.Equals(TextAlignment.Right)); RadioJust.IsChecked = (temp != DependencyProperty.UnsetValue) && (temp.Equals(TextAlignment.Justify)); //тут применяется шрифт и размер шрифта temp = MainTextBox.Selection.GetPropertyValue(Inline.FontFamilyProperty); ComboFontType.SelectedItem = temp; if (!ComboFontSize.Items.Equals("")) { temp = MainTextBox.Selection.GetPropertyValue(Inline.FontSizeProperty); ComboFontSize.Text = temp.ToString(); } else { ComboFontSize.SelectedIndex = 0; } }
private void editor_SelectionChanged(object sender, RoutedEventArgs e) { TextPointer tp1 = editor.Selection.Start.GetLineStartPosition(0); TextPointer tp2 = editor.Selection.Start; int column = tp1.GetOffsetToPosition(tp2); int someBigNumber = int.MaxValue; int lineMoved, currentLineNumber; editor.Selection.Start.GetLineStartPosition(-someBigNumber, out lineMoved); currentLineNumber = -lineMoved; long size = 0; object o = new object(); StatusBar.Content = "Лінія: " + currentLineNumber.ToString() + " Колонка: " + column.ToString(); }
/// <summary> /// Computes the line and column a <see cref="Word"/> is located in the code. /// </summary> /// <param name="word">A <see cref="Word"/> which exists in the code.</param> /// <returns>An array, which contains the line at the index 0 and the column at the index 1.</returns> private static int[] GetLineAndColumn(Word word) { int[] lineAndColumn = { 1, 1 }; int lineNumber; word.StartPosition.GetLineStartPosition(-int.MaxValue, out lineNumber); TextPointer lineStartPosition = word.StartPosition.GetLineStartPosition(0); if (lineStartPosition != null) { int columnNumber = lineStartPosition.GetOffsetToPosition(word.StartPosition); if (lineNumber == 0) { columnNumber--; } lineAndColumn[0] = -lineNumber + 1; lineAndColumn[1] = columnNumber + 1; } return(lineAndColumn); }