<i id='zwVxr'><tr id='zwVxr'><dt id='zwVxr'><q id='zwVxr'><span id='zwVxr'><b id='zwVxr'><form id='zwVxr'><ins id='zwVxr'></ins><ul id='zwVxr'></ul><sub id='zwVxr'></sub></form><legend id='zwVxr'></legend><bdo id='zwVxr'><pre id='zwVxr'><center id='zwVxr'></center></pre></bdo></b><th id='zwVxr'></th></span></q></dt></tr></i><div id='zwVxr'><tfoot id='zwVxr'></tfoot><dl id='zwVxr'><fieldset id='zwVxr'></fieldset></dl></div>
  1. <small id='zwVxr'></small><noframes id='zwVxr'>

      <legend id='zwVxr'><style id='zwVxr'><dir id='zwVxr'><q id='zwVxr'></q></dir></style></legend>

        <bdo id='zwVxr'></bdo><ul id='zwVxr'></ul>

      <tfoot id='zwVxr'></tfoot>

      文本框文本颜色更改

      时间:2023-06-09
        • <bdo id='GKWNi'></bdo><ul id='GKWNi'></ul>
        • <legend id='GKWNi'><style id='GKWNi'><dir id='GKWNi'><q id='GKWNi'></q></dir></style></legend>

          <i id='GKWNi'><tr id='GKWNi'><dt id='GKWNi'><q id='GKWNi'><span id='GKWNi'><b id='GKWNi'><form id='GKWNi'><ins id='GKWNi'></ins><ul id='GKWNi'></ul><sub id='GKWNi'></sub></form><legend id='GKWNi'></legend><bdo id='GKWNi'><pre id='GKWNi'><center id='GKWNi'></center></pre></bdo></b><th id='GKWNi'></th></span></q></dt></tr></i><div id='GKWNi'><tfoot id='GKWNi'></tfoot><dl id='GKWNi'><fieldset id='GKWNi'></fieldset></dl></div>
            <tbody id='GKWNi'></tbody>

            1. <tfoot id='GKWNi'></tfoot>

            2. <small id='GKWNi'></small><noframes id='GKWNi'>

              1. 本文介绍了文本框文本颜色更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有 textbox textbox1 我想更改文本颜色,但在所有文本的一部分.例如从 /**/ 就像 Visual Studio 中的注释?

                I have textbox textbox1 and I want to change text color, but in the part of all text. For example from /* to */ like comments in visual studio?

                我该怎么做?

                推荐答案

                试试这个:

                TextRange rangeOfText1 = new TextRange(richTextBox.Document.ContentEnd, richTextBox.Document.ContentEnd);
                rangeOfText1.Text = "Text1 ";
                rangeOfText1.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Blue);
                rangeOfText1.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
                
                TextRange rangeOfWord = new TextRange(richTextBox.Document.ContentEnd, richTextBox.Document.ContentEnd);
                rangeOfWord.Text = "word ";
                rangeOfWord.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);
                rangeOfWord.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Regular);
                
                TextRange rangeOfText2 = new TextRange(richTextBox.Document.ContentEnd, richTextBox.Document.ContentEnd);
                rangeOfText2.Text = "Text2 ";
                rangeOfText2.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Blue);
                rangeOfText2.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
                

                或者这个:

                public TestWindow()
                {
                InitializeComponent();
                
                this.paragraph = new Paragraph();
                rich1.Document = new FlowDocument(paragraph);
                
                var from = "user1";
                var text = "chat message goes here";
                paragraph.Inlines.Add(new Bold(new Run(from + ": "))
                {
                    Foreground = Brushes.Red
                });
                paragraph.Inlines.Add(text);
                paragraph.Inlines.Add(new LineBreak());
                this.DataContext = this;
                }
                private Paragraph paragraph;
                

                来源:

                更改颜色和WPF C#中部分文本的字体

                和 MSDN:

                http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.document.aspx

                这篇关于文本框文本颜色更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:遍历 asp.net 中的 TextBoxes - 为什么这不起作用? 下一篇:如何将 WinForms 文本框设置为覆盖模式

                相关文章

                  <small id='rbH7t'></small><noframes id='rbH7t'>

                1. <i id='rbH7t'><tr id='rbH7t'><dt id='rbH7t'><q id='rbH7t'><span id='rbH7t'><b id='rbH7t'><form id='rbH7t'><ins id='rbH7t'></ins><ul id='rbH7t'></ul><sub id='rbH7t'></sub></form><legend id='rbH7t'></legend><bdo id='rbH7t'><pre id='rbH7t'><center id='rbH7t'></center></pre></bdo></b><th id='rbH7t'></th></span></q></dt></tr></i><div id='rbH7t'><tfoot id='rbH7t'></tfoot><dl id='rbH7t'><fieldset id='rbH7t'></fieldset></dl></div>
                2. <tfoot id='rbH7t'></tfoot>

                  • <bdo id='rbH7t'></bdo><ul id='rbH7t'></ul>
                  <legend id='rbH7t'><style id='rbH7t'><dir id='rbH7t'><q id='rbH7t'></q></dir></style></legend>