C# 如何为同一标签使用粗体文字和普通文字?
我需要有我的标签控件作为粗体和正常字符的文本 我该怎么做?有什么想法或建议吗 谢谢 编辑: 这是Winform,很抱歉,但我不知道,我使用两个标签,但我只想使用一个C# 如何为同一标签使用粗体文字和普通文字?,c#,winforms,C#,Winforms,我需要有我的标签控件作为粗体和正常字符的文本 我该怎么做?有什么想法或建议吗 谢谢 编辑: 这是Winform,很抱歉,但我不知道,我使用两个标签,但我只想使用一个 有可能吗 我做过这样的事情 using (Graphics g = Graphics.FromImage(pictureBox1.Image)) { Font drawFont = new Font("Arial", 12); Font drawFontBold = new Font(
有可能吗 我做过这样的事情
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 event并按照我为lable所做的方式绘制,我认为答案可能与您相关:
使用样式化的RichTextBox而不是标签,选择文本并将其设置为粗体。欢迎使用堆栈溢出。这不是一个好的提问方式。到目前为止,你有没有尝试过解决你的问题?先表现出你的努力,这样人们才能表现出他们的努力。请阅读,作为一个开始,你尝试过什么吗?Winforms,WPF,或者其他什么?我有一个例子