【问题标题】:How to have text with bold and normal words for same label?如何为相同的标签添加粗体和普通单词的文本?
【发布时间】:2014-09-05 07:15:47
【问题描述】:

我需要为我的标签控件设置粗体和普通字符的文本。

我该怎么做?有什么想法或指点吗??

谢谢。

编辑:

这是 Winform,很抱歉,我不知道,我为此使用了两个标签,但我只想使用一个。

有可能吗。!!

【问题讨论】:

  • 欢迎来到 Stack Overflow。这不是在这里提问的好方法。到目前为止,您是否尝试过任何方法来解决您的问题?首先展示你的努力,这样人们就可以展示他们的努力。请阅读FAQHow to Askhelp center 作为开始..
  • 你有没有尝试过?
  • Winforms、WPF 还是其他?
  • 我有一个例子here

标签: c# winforms


【解决方案1】:

我认为答案可能与您相关: https://stackoverflow.com/a/2527744/3835956

使用样式化的 RichTextBox 而不是标签,选择文本并将其设置为粗体。

【讨论】:

    【解决方案2】:

    我做过类似的事情,

       using (Graphics g = Graphics.FromImage(pictureBox1.Image))
        {
    
            Font drawFont = new Font("Arial", 12);
            Font drawFontBold = new Font("Arial", 12, FontStyle.Bold);
            SolidBrush drawBrush = new SolidBrush(Color.Black);
    
            // find the width of single char using selected fonts
            float CharWidth = g.MeasureString("Y", drawFont).Width;
    
            // draw first part of string
            g.DrawString("this is normal", drawFont, drawBrush, new RectangleF(350f, 250f, 647, 200));
            // now get the total width of words drawn using above settings
            float widthFirst = ("this is normal").Length() * CharWidth;
    
            // the width of first part string to start of second part to avoid overlay
            g.DrawString(" and this is bold text", drawFontBold, drawBrush, new RectangleF(350f + widthFirst, 250f, 647, 200));
        }
    

    希望对你有帮助..!!!

    注意 您可以使用 Label Paint 事件并按照我为 lable 所做的方式绘制

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-28
      • 1970-01-01
      • 2019-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多