private void ApplyFormatClick(object sender, RoutedEventArgs e) { Stopwatch stopwatch = Stopwatch.StartNew(); FlowDocument doc = Rtb.Document; TextRange range = new TextRange(doc.ContentStart, doc.ContentEnd); range.ClearAllProperties(); int i = 0; while (true) { TextPointer p1 = range.Start.GetPositionAtOffset(i); i++; TextPointer p2 = range.Start.GetPositionAtOffset(i); if (p2 == null) break; TextRange tempRange = new TextRange(p1, p2); if (tempRange != null) { tempRange.ApplyPropertyValue(TextElement.ForegroundProperty, _blueBrush); tempRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold); } i++; } Time.Text = "Formatting took: " + stopwatch.ElapsedMilliseconds + " ms, number of characters: " + range.Text.Length; }
public void Apply(swd.TextRange range) { range.ApplyPropertyValue(swd.TextElement.FontFamilyProperty, Control.FontFamily); range.ApplyPropertyValue(swd.TextElement.FontStyleProperty, Control.Style); range.ApplyPropertyValue(swd.TextElement.FontStretchProperty, Control.Stretch); range.ApplyPropertyValue(swd.TextElement.FontWeightProperty, Control.Weight); }
public void Update() { ChatText.Document.Blocks.Clear(); ChatPlayerItem tempItem = null; foreach (KeyValuePair<string, ChatPlayerItem> x in Client.AllPlayers) { if (x.Value.Username == (string)Client.ChatItem.PlayerLabelName.Content) { tempItem = x.Value; break; } } foreach (string x in tempItem.Messages.ToArray()) { string[] Message = x.Split('|'); TextRange tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd); if (Message[0] == tempItem.Username) { tr.Text = tempItem.Username + ": "; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Gold); } else { tr.Text = Message[0] + ": "; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.SteelBlue); } tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd); tr.Text = x.Replace(Message[0] + "|", "") + Environment.NewLine; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White); } ChatText.ScrollToEnd(); }
public void Apply(swd.TextRange control) { control.ApplyPropertyValue(swd.TextElement.FontFamilyProperty, WpfFamily); control.ApplyPropertyValue(swd.TextElement.FontStyleProperty, WpfFontStyle); control.ApplyPropertyValue(swd.TextElement.FontWeightProperty, WpfFontWeight); control.ApplyPropertyValue(swd.TextElement.FontSizeProperty, PixelSize); control.ApplyPropertyValue(swd.Inline.TextDecorationsProperty, WpfTextDecorations); }
public void Format() { for (int i = 0; i < _ranges.Count; i++) { TextRange range = new TextRange(_ranges[i].StartPosition, _ranges[i].EndPosition); range.ApplyPropertyValue(TextElement.ForegroundProperty, _ranges[i].Foreground); range.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold); } _ranges.Clear(); }
/// <summary> /// Extension method for writing color to a RichTextBox. /// </summary> /// <param name="box">the RichTextBox to be written to.</param> /// <param name="text">the text to be written to the RichTextBox.</param> /// <param name="color">the color of the text, defined by the Color structure.</param> /// <param name="sameLine">True if the text is to be written to the same line as the last text.</param> public static void AppendText(this RichTextBox box, string text, string color, bool sameLine) { BrushConverter bc = new BrushConverter(); TextRange tr = new TextRange(box.Document.ContentEnd, box.Document.ContentEnd); if (!sameLine) tr.Text = "\r\n" + text; else tr.Text = text; try { tr.ApplyPropertyValue(TextElement.ForegroundProperty, bc.ConvertFromString(color)); } catch (FormatException) { tr.ApplyPropertyValue(TextElement.ForegroundProperty, bc.ConvertFromString("Black")); } }
public virtual void ApplyToRange(TextRange range, IConsoleColorMap colorMap) { if (DefaultBackground != null) { range.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(colorMap.MapBackground(DefaultBackground.Value))); } if (DefaultForeground != null) { range.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(colorMap.MapBackground(DefaultForeground.Value))); } }
/// <summary> /// Extension method for writing color to a RichTextBox. /// </summary> /// <param name="box">the RichTextBox to be written to.</param> /// <param name="text">the text to be written to the RichTextBox.</param> /// <param name="color">the color of the text, defined by the Color structure.</param> public static void AppendText(this RichTextBox box, string text, string color) { //initialize a class to convert strings to brush colors BrushConverter bc = new BrushConverter(); //initialize a class for writing to a richtextbox TextRange tr = new TextRange(box.Document.ContentEnd, box.Document.ContentEnd); tr.Text = "\r\n" + text; //try to write the color given try { tr.ApplyPropertyValue(TextElement.ForegroundProperty, bc.ConvertFromString(color)); } //if it fails, write it in black catch (FormatException) { tr.ApplyPropertyValue(TextElement.ForegroundProperty, bc.ConvertFromString("Black")); } }
public TextFormatter(string message) { IsPage = IsWhisper = IsNotify = false; FormattedRun = new Run(message); if (page.IsMatch(message)) { TextRange range = new TextRange(FormattedRun.ContentStart, FormattedRun.ContentEnd); range.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.DarkGreen); range.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.ExtraBold); IsPage = true; } else if (whisper.IsMatch(message)) { TextRange range = new TextRange(FormattedRun.ContentStart, FormattedRun.ContentEnd); range.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.DarkBlue); range.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Italic); IsWhisper = true; } else if (message[0] == '#') { TextRange range = new TextRange(FormattedRun.ContentStart, FormattedRun.ContentEnd); range.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.LightGray); } else if (message[0] == '<') { TextRange range = new TextRange(FormattedRun.ContentStart, FormattedRun.ContentEnd); range.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red); range.ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.Cyan); range.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.ExtraBold); IsNotify = true; } else if (message.IndexOf("Somewhere on the muck") == 0) { TextRange range = new TextRange(FormattedRun.ContentStart, FormattedRun.ContentEnd); range.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.DarkSlateGray); IsConnect = true; } }
public void Write (string s) { // Capture state locally var fore = _Fore; var back = _Back; _RTF.Dispatcher.BeginInvoke ((Action) (() => { var range = new TextRange (_RTF.Document.ContentEnd, _RTF.Document.ContentEnd); range.Text = s; range.ApplyPropertyValue (TextElement.ForegroundProperty, new SolidColorBrush (fore)); range.ApplyPropertyValue (TextElement.BackgroundProperty, new SolidColorBrush (back)); _RTF.ScrollToEnd (); })); }
// Event handler void LogTextChanged(object sender, TextChangedEventArgs e) { RichTextBox textView = (RichTextBox)sender; TextRange completeContent = new TextRange(textView.Document.ContentStart, textView.Document.ContentEnd); string logContent = completeContent.Text; // highlight the text to search if (FindLogTextBox.Text.Length > 0) { // http://msdn.microsoft.com/en-us/library/system.windows.documents.textpointer.aspx TextPointer position = textView.Document.ContentStart; while (position != null) { if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text) { string textRun = position.GetTextInRun(LogicalDirection.Forward); int indexInRun = textRun.IndexOf(FindLogTextBox.Text); if (indexInRun >= 0) { TextPointer start = position.GetPositionAtOffset(indexInRun); TextPointer end = start.GetPositionAtOffset(FindLogTextBox.Text.Length); var textRange = new TextRange(start, end); textRange.ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.Red); } } position = position.GetNextContextPosition(LogicalDirection.Forward); } } }
private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { if (this.Visibility == Visibility.Visible) { // Show the story, hide the editor StoryViewBorder.Visibility = Visibility.Visible; StoryEditBorder.Visibility = Visibility.Hidden; // Load the person story into the viewer LoadStoryText(StoryViewer.Document); // Display all text in constrast color to the StoryViewer background. TextRange textRange2 = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd); textRange2.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd); textRange2.ApplyPropertyValue(TextElement.ForegroundProperty, FindResource("FlowDocumentFontColor")); // Hide the photo tags and photo edit buttons if there is no main photo. if (DisplayPhoto.Source == null) { TagsStackPanel.Visibility = Visibility.Hidden; PhotoButtonsDockPanel.Visibility = Visibility.Hidden; } // Workaround to get the StoryViewer to display the first page instead of the last page when first loaded StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Scroll; StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Page; } }
/// <summary> /// The details of a person changed. /// </summary> public void OnSkinChanged() { // Display all text in constrast color to the StoryViewer background. TextRange textRange = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd); textRange.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd); textRange.ApplyPropertyValue(TextElement.ForegroundProperty, FindResource("FlowDocumentFontColor")); }
/// <summary> /// Append text to RichTextBox with red coloring; for errors /// </summary> /// <param name="targetBox">Box to append text to</param> /// <param name="text">Error text to append</param> private void appendErrorText(RichTextBox targetBox, string text) { // Append text with automatic styling for error text TextRange tr = new TextRange(targetBox.Document.ContentEnd, targetBox.Document.ContentEnd); tr.Text = text; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red); }
public TypefaceListItem(Typeface typeface) { _displayName = GetDisplayName(typeface); _simulated = typeface.IsBoldSimulated || typeface.IsObliqueSimulated; this.FontFamily = typeface.FontFamily; this.FontWeight = typeface.Weight; this.FontStyle = typeface.Style; this.FontStretch = typeface.Stretch; string itemLabel = _displayName; //if (_simulated) //{ // string formatString = EpiDashboard.Properties.Resources.ResourceManager.GetString( // "simulated", // CultureInfo.CurrentUICulture // ); // itemLabel = string.Format(formatString, itemLabel); //} this.Text = itemLabel; this.ToolTip = itemLabel; // In the case of symbol font, apply the default message font to the text so it can be read. if (FontFamilyListItem.IsSymbolFont(typeface.FontFamily)) { TextRange range = new TextRange(this.ContentStart, this.ContentEnd); range.ApplyPropertyValue(TextBlock.FontFamilyProperty, SystemFonts.MessageFontFamily); } }
void XmppConnection_OnMessage(object sender, Message msg) { if (!roomName.Contains(msg.From.User)) return; if (msg.From.Resource == Client.LoginPacket.AllSummonerData.Summoner.Name) return; Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { if (msg.Body == "This room is not anonymous") return; var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = msg.From.Resource + ": " }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Turquoise); tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = msg.Body.Replace("<![CDATA[", "").Replace("]]>", string.Empty) + Environment.NewLine }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White); ChatText.ScrollToEnd(); })); }
void SetDecorations(swd.TextRange range, sw.TextDecorationCollection decorations, bool value) { var existingDecorations = range.GetPropertyValue(swd.Inline.TextDecorationsProperty) as sw.TextDecorationCollection; if (existingDecorations != null) { existingDecorations = new sw.TextDecorationCollection(existingDecorations); } if (value) { existingDecorations = existingDecorations ?? new sw.TextDecorationCollection(); existingDecorations.Add(decorations); } else if (existingDecorations != null) { foreach (var decoration in decorations) { if (existingDecorations.Contains(decoration)) { existingDecorations.Remove(decoration); } } if (existingDecorations.Count == 0) { existingDecorations = null; } } range.ApplyPropertyValue(swd.Inline.TextDecorationsProperty, existingDecorations); }
public RichTextBoxToolbar() { SpecialInitializeComponent(); cmbFontFamily.SelectionChanged += (s, e) => { if (cmbFontFamily.SelectedValue != null && RichTextBox != null) { TextRange tr = new TextRange(RichTextBox.Selection.Start, RichTextBox.Selection.End); var value = cmbFontFamily.SelectedValue; tr.ApplyPropertyValue(TextElement.FontFamilyProperty, value); } }; cmbFontSize.SelectionChanged += (s, e) => { if (cmbFontSize.SelectedValue != null && RichTextBox != null) { TextRange tr = new TextRange(RichTextBox.Selection.Start, RichTextBox.Selection.End); var value = ((ComboBoxItem)cmbFontSize.SelectedValue).Content.ToString(); tr.ApplyPropertyValue(TextElement.FontSizeProperty, double.Parse(value)); } }; cmbFontSize.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler((s, e) => { if (!string.IsNullOrEmpty(cmbFontSize.Text) && RichTextBox != null) { TextRange tr = new TextRange(RichTextBox.Selection.Start, RichTextBox.Selection.End); tr.ApplyPropertyValue(TextElement.FontSizeProperty, double.Parse(cmbFontSize.Text)); } })); }
public void ShowLobbyMessage(string message) { var tr = new TextRange(output.Document.ContentEnd, output.Document.ContentEnd); tr.Text = message + '\n'; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red); if (scroller.VerticalOffset == scroller.ScrollableHeight) scroller.ScrollToBottom(); }
public TypefaceListItem(Typeface typeface) { _displayName = GetDisplayName(typeface); _simulated = typeface.IsBoldSimulated || typeface.IsObliqueSimulated; FontFamily = typeface.FontFamily; FontWeight = typeface.Weight; FontStyle = typeface.Style; FontStretch = typeface.Stretch; var itemLabel = _displayName; if (_simulated) { var formatString = Properties.Resources.ResourceManager.GetString( "simulated", CultureInfo.CurrentUICulture ); itemLabel = string.Format(formatString, itemLabel); } Text = itemLabel; ToolTip = itemLabel; // In the case of symbol font, apply the default message font to the text so it can be read. if (FontFamilyListItem.IsSymbolFont(typeface.FontFamily)) { var range = new TextRange(ContentStart, ContentEnd); range.ApplyPropertyValue(FontFamilyProperty, SystemFonts.MessageFontFamily); } }
/// <summary> /// Writes to the emulator. /// </summary> /// <param name="Text">The text.</param> public void WriteLine(string Text) { if (string.IsNullOrEmpty(Text)) return; Text = Text.Replace("\u001b", ""); //AllocConsole(); this.Dispatcher.Invoke(new Action(()=> { Regex MatchRegex = new Regex("\\[(\\d+)(;(\\d+))?m", RegexOptions.IgnoreCase); int lastIndex = 0; // Match the regular expression pattern against a text string. Match TextMatch = MatchRegex.Match(Text); Match NextMatch; TextRange RangeForNewText = new TextRange(RichTextBox.Document.ContentEnd, RichTextBox.Document.ContentEnd); int BackgroundColor = 255; int ForegroundColor = 0; Console.WriteLine(Text); if (TextMatch.Success) { RangeForNewText.Text = Text.Substring(0, TextMatch.Index); } while (TextMatch.Success) { BackgroundColor = Convert.ToInt32(TextMatch.Groups[3].Value != "" ? TextMatch.Groups[3].Value : "0"); // ;number ForegroundColor = Convert.ToInt32(TextMatch.Groups[1].Value); BackgroundColor = BackgroundColor == 0 ? BackgroundColor : Math.Abs((BackgroundColor - 40) % 7); ForegroundColor = ForegroundColor == 0 ? ForegroundColor : Math.Abs((ForegroundColor - 30) % 7); RangeForNewText = new TextRange(RichTextBox.Document.ContentEnd, RichTextBox.Document.ContentEnd); NextMatch = TextMatch.NextMatch(); lastIndex = TextMatch.Index + TextMatch.Length; RangeForNewText.Text = NextMatch.Success ? Text.Substring(lastIndex, NextMatch.Index - lastIndex) : Text.Substring(lastIndex); RangeForNewText.ApplyPropertyValue(TextElement.BackgroundProperty, (ColorMap[BackgroundColor])); RangeForNewText.ApplyPropertyValue(TextElement.ForegroundProperty, (ColorMap[ForegroundColor])); //rangeOfWord.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Regular); Console.WriteLine("ORIG =" + Text); Console.WriteLine("bg =" + BackgroundColor + ", fr = " + ForegroundColor + ", text =" + RangeForNewText.Text); TextMatch = NextMatch; } RangeForNewText = new TextRange(RichTextBox.Document.ContentEnd, RichTextBox.Document.ContentEnd) { Text = Text.Substring(lastIndex) + "\u2028"//System.Environment.NewLine }; RangeForNewText.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White); RangeForNewText.ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.Black); RichTextBox.ScrollToEnd(); })); }
void AppendText(RichTextBox box, Brush color, string text) { TextPointer end = box.Document.ContentEnd; TextRange tr = new TextRange(end, end); tr.Text = text; tr.ApplyPropertyValue(TextElement.ForegroundProperty, color); box.ScrollToEnd(); }
public static void WriteLogException(string message) { TextRange tr = new TextRange(LogBox.Document.ContentStart, LogBox.Document.ContentStart); string TimePattern = DateTime.Now.ToString("dd/MM/yy HH:mm:ss.fff") + " | >>> "; tr.Text = TimePattern + message + "\n"; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red); }
public static void WriteLogInfo(string info) { TextRange tr = new TextRange(LogBox.Document.ContentEnd, LogBox.Document.ContentEnd); string TimePattern = DateTime.Now.ToString("dd/MM/yy HH:mm:ss.fff") + " | >>> "; tr.Text = TimePattern + info + "\n"; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Black); }
private void newRoom_OnParticipantJoin(Room room, RoomParticipant participant) { Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { TextRange tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd); tr.Text = participant.Nick + " joined the room." + Environment.NewLine; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow); })); }
//Здесь у обжект будем передавать цвет Brushes.Color!!! public void Log(RichTextBox box1, string msg, object color) { box1.Dispatcher.Invoke(new Action(() => { TextRange range = new TextRange(box1.Document.ContentEnd, box1.Document.ContentEnd); range.Text = msg; range.ApplyPropertyValue(TextElement.ForegroundProperty, color); box1.ScrollToEnd();// функция Autoscroll })); }
private void AppendLineToRichTextBox(string text, SolidColorBrush color) { // Report progress by sending an action that will be invoked // on a main thread and append text to a rich text box backgroundWorker.ReportProgress(0, new Action(() => { TextRange tr = new TextRange(richTextBox.Document.ContentEnd, richTextBox.Document.ContentEnd); tr.Text = Environment.NewLine + text; tr.ApplyPropertyValue(TextElement.ForegroundProperty, color); })); }
public static TextPointer RemoveHyperlink(TextPointer start) { var backspacePosition = start.GetNextInsertionPosition(LogicalDirection.Backward); Hyperlink hyperlink; if (backspacePosition == null || !IsHyperlinkBoundaryCrossed(start, backspacePosition, out hyperlink)) { return null; } // Remember caretPosition with forward gravity. This is necessary since we are going to delete // the hyperlink element preceeding caretPosition and after deletion current caretPosition // (with backward gravity) will follow content preceeding the hyperlink. // We want to remember content following the hyperlink to set new caret position at. var newCaretPosition = start.GetPositionAtOffset(0, LogicalDirection.Forward); // Deleting the hyperlink is done using logic below. // 1. Copy its children Inline to a temporary array. var hyperlinkChildren = hyperlink.Inlines; var inlines = new Inline[hyperlinkChildren.Count]; hyperlinkChildren.CopyTo(inlines, 0); // 2. Remove each child from parent hyperlink element and insert it after the hyperlink. for (int i = inlines.Length - 1; i >= 0; i--) { hyperlinkChildren.Remove(inlines[i]); hyperlink.SiblingInlines.InsertAfter(hyperlink, inlines[i]); } // 3. Apply hyperlink's local formatting properties to inlines (which are now outside hyperlink scope). var localProperties = hyperlink.GetLocalValueEnumerator(); var inlineRange = new TextRange(inlines[0].ContentStart, inlines[inlines.Length - 1].ContentEnd); while (localProperties.MoveNext()) { var property = localProperties.Current; var dp = property.Property; object value = property.Value; if (!dp.ReadOnly && dp != Inline.TextDecorationsProperty && // Ignore hyperlink defaults. dp != TextElement.ForegroundProperty && dp != BaseUriHelper.BaseUriProperty && !IsHyperlinkProperty(dp)) { inlineRange.ApplyPropertyValue(dp, value); } } // 4. Delete the (empty) hyperlink element. hyperlink.SiblingInlines.Remove(hyperlink); return newCaretPosition; }
public void Highlight(FlowDocument targetDocument, string text) { TextPointer start = targetDocument.ContentStart; foreach (Match m in SingleLineCommentRegex.Matches(text)) { TextPointer matchStart = start.GetPositionAtOffset(m.Index); TextPointer matchEnd = matchStart.GetPositionAtOffset(m.Length); TextRange range = new TextRange(matchStart, matchEnd); range.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.LimeGreen); } }
private void ChatButton_Click(object sender, RoutedEventArgs e) { TextRange tr = new TextRange(ChatTextThing.Document.ContentEnd, ChatTextThing.Document.ContentEnd); tr.Text = Client.LoginPacket.AllSummonerData.Summoner.Name + ": "; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow); tr = new TextRange(ChatTextThing.Document.ContentEnd, ChatTextThing.Document.ContentEnd); tr.Text = ChatTextBox.Text + Environment.NewLine; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White); newRoom.PublicMessage(ChatTextBox.Text); ChatTextBox.Text = ""; }
void ApplySelectionAttributes(swd.TextRange range, Dictionary <sw.DependencyProperty, object> attributes) { if (attributes == null) { return; } foreach (var attribute in attributes) { range.ApplyPropertyValue(attribute.Key, attribute.Value); } }
public static Font SetEtoFont(this swd.TextRange control, Font font) { if (control == null) { return(font); } if (font != null) { ((FontHandler)font.Handler).Apply(control); } else { control.ApplyPropertyValue(swd.TextElement.FontFamilyProperty, swc.Control.FontFamilyProperty.DefaultMetadata.DefaultValue); control.ApplyPropertyValue(swd.TextElement.FontStyleProperty, swc.Control.FontStyleProperty.DefaultMetadata.DefaultValue); control.ApplyPropertyValue(swd.TextElement.FontWeightProperty, swc.Control.FontWeightProperty.DefaultMetadata.DefaultValue); control.ApplyPropertyValue(swd.TextElement.FontSizeProperty, swc.Control.FontSizeProperty.DefaultMetadata.DefaultValue); control.ApplyPropertyValue(swd.Inline.TextDecorationsProperty, new sw.TextDecorationCollection()); } return(font); }
public void colorearLinea(int LineNumber, Color color) { try { TextPointer start = txt.CaretPosition.GetLineStartPosition(LineNumber); TextPointer stop = txt.CaretPosition.GetLineStartPosition(LineNumber + 1); TextRange textrange = new TextRange(start, stop); textrange.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(color)); }catch{} }
private void AppendText(RichTextBox box, string text, string color) { BrushConverter bc = new BrushConverter(); TextRange tr = new TextRange(box.Document.ContentEnd, box.Document.ContentEnd); tr.Text = text; try { tr.ApplyPropertyValue(TextElement.ForegroundProperty, bc.ConvertFromString(color)); } catch (FormatException) { } }
private void Lobby_ChatMessage(object sender, ChatMessageEventArgs e) { dispatch.Invoke(() => { var tr = new TextRange(output.Document.ContentEnd, output.Document.ContentEnd); tr.Text = e.From + ": "; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.CornflowerBlue); tr = new TextRange(output.Document.ContentEnd, output.Document.ContentEnd); tr.Text = e.Message + '\n'; tr.ApplyPropertyValue(TextElement.ForegroundProperty, App.FontBrush); if (scroller.VerticalOffset == scroller.ScrollableHeight) scroller.ScrollToBottom(); }); }
public static FontFamily SetEtoFamily(this swd.TextRange control, FontFamily fontFamily) { if (control == null) { return(fontFamily); } if (fontFamily != null) { ((FontFamilyHandler)fontFamily.Handler).Apply(control); } else { control.ApplyPropertyValue(swd.TextElement.FontFamilyProperty, swc.Control.FontFamilyProperty.DefaultMetadata.DefaultValue); } return(fontFamily); }
public void Apply(sw.Documents.TextRange control) { control.ApplyPropertyValue(swd.TextElement.FontFamilyProperty, Control); }