• <bdo id='Raaqz'></bdo><ul id='Raaqz'></ul>

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

      <tfoot id='Raaqz'></tfoot>

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

        在 TextBox 中使特定文本加粗

        Making specific Text Boldefaced in a TextBox(在 TextBox 中使特定文本加粗)

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

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

                • 本文介绍了在 TextBox 中使特定文本加粗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前有一个 texbox,当用户按下不同的按钮时,它会向用户打印信息.我想知道是否有办法让我的部分文本只加粗,而其余部分不加粗.

                  Hi I currently have a texbox that prints out info to the user when they press diffrent buttons. I was wondering if there was a way to make only some of my text bolded while the rest isnt.

                  我尝试了以下方法:

                  textBox1.FontWeight = FontWeights.UltraBold;
                  textBox1.Text. = ("Your Name: " );
                  TextBox1.FontWeight = FontWeights.Regular;
                  textBox1.Text += (nameVar);
                  

                  唯一的问题是,使用这种方式要么使所有内容变得粗体,要么什么都没有.有没有办法做到这一点?我在 C# 中使用 WPF 项目

                  Only problem is that using this way will either make everything bold or nothing. Is there a way to do this? Im using WPF project in C#

                  任何意见或建议表示赞赏.谢谢!

                  Any Comments or suggestions are appreciated. Thanks!

                  所以现在我正在尝试执行你们都建议的 RichText 框,但我似乎无法在其中出现任何内容:

                  So now im trying to do the RichText box that you all suggested but I cant seem to get anything to appear in it:

                  // Create a simple FlowDocument to serve as the content input for the construtor.
                  FlowDocument flowDoc = new FlowDocument(new Paragraph(new Run("Simple FlowDocument")));
                  // After this constructor is called, the new RichTextBox rtb will contain flowDoc.
                  RichTextBox rtb = new RichTextBox(flowDoc);
                  

                  rtb 是我在 wpf 中创建的富文本框的名称

                  rtb is the name of my richtextbox i created in my wpf

                  谢谢

                  推荐答案

                  在我为这个问题编写的方法下方使用 RichTextBox - 希望它有所帮助;-)

                  use a RichTextBox, below a method that i have wrote for this problem - hope it helps ;-)

                  /// <summary>
                  /// This method highlights the assigned text with the specified color.
                  /// </summary>
                  /// <param name="textToMark">The text to be marked.</param>
                  /// <param name="color">The new Backgroundcolor.</param>
                  /// <param name="richTextBox">The RichTextBox.</param>
                  /// <param name="startIndex">The zero-based starting caracter position.</param>
                  public static void ChangeTextcolor(string textToMark, Color color, RichTextBox richTextBox, int startIndex)
                  {
                      if (startIndex < 0 || startIndex > textToMark.Length-1) startIndex = 0;
                  
                      System.Drawing.Font newFont = new Font("Verdana", 10f, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 178, false);
                      try
                      {               
                          foreach (string line in richTextBox.Lines)
                          { 
                              if (line.Contains(textToMark))
                              {
                                  richTextBox.Select(startIndex, line.Length);
                                  richTextBox.SelectionBackColor = color;
                              }
                              startIndex += line.Length +1;
                          }
                      }
                      catch
                      { }
                  }
                  

                  这篇关于在 TextBox 中使特定文本加粗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to keep the Text of a Read only TextBox after PostBack()?(PostBack()之后如何保留只读文本框的文本?)
                  Winforms Textbox - Using Ctrl-Backspace to Delete Whole Word(Winforms 文本框 - 使用 Ctrl-Backspace 删除整个单词)
                  C# - Add button click events using code(C# - 使用代码添加按钮单击事件)
                  Multi-color TextBox C#(多色文本框 C#)
                  How can i set the caret position to a specific index in passwordbox in WPF(如何将插入符号位置设置为 WPF 密码框中的特定索引)
                  C# Numeric Only TextBox Control(C# 纯数字文本框控件)
                  <tfoot id='r03Cs'></tfoot>
                  <legend id='r03Cs'><style id='r03Cs'><dir id='r03Cs'><q id='r03Cs'></q></dir></style></legend>

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

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

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

                            <tbody id='r03Cs'></tbody>