【问题标题】:Changing the color of a part of a label in c#在c#中更改标签部分的颜色
【发布时间】:2018-06-16 15:13:57
【问题描述】:

我想将标签中的部分文本更改为另一种颜色并且更大一点,例如使用蓝色或任何其他颜色并且更大一点的年份,因为我要上课我想保留这一年,其余的都和以前一样黑

            label3.Width = pictureBox1.Width*2-100;
            label3.Top = pictureBox1.Top + pictureBox1.Height-50;
            label3.Left = pictureBox1.Left-75;
            label3.Height = 200;
            label3.Text = "Regele Carol al II-lea(1930-1940) si fiul sau Mihai I(9 ani) cu prilejul " +
                "proclamarii principelui Carol al II-lea, Rege al Romaniei, de catre Parlamewntul " +
                "de la Bucuresti, la 8 Iunie 1930";

            label4.Width = pictureBox2.Width * 2 - 75;
            label4.Top = pictureBox2.Top + pictureBox2.Height - 50;
            label4.Left = pictureBox2.Left - 75;
            label4.Height = 150;
            label4.Text = "Clasa de elevi cu Mihai I ce poarta titlul de: 'Mare Voievod de ALBA IULIA' in 1937, de Craciun 25 XII";

【问题讨论】:

标签: c# text colors label


【解决方案1】:

假设您确实想要在 same 标签中使用不同的颜色和字体,我建议您使用 RichTextBox 而不是 Label,就像在 Rotem 的重复提案中提到的那样。它很容易使用:

RichTextBox rtb1 = new RichTextBox();
rtb1.SelectionColor = Color.Red;
rtb1.AppendText("Hello ");
rtb1.SelectionColor = Color.Green;
rtb1.AppendText("World");

RichTextBox.SelectionFont 也是如此...

编辑:为了完整起见 - 以下是使其看起来/反应像标签的更改:

rtb1.BackColor = System.Drawing.SystemColors.Control;
rtb1.BorderStyle = System.Windows.Forms.BorderStyle.None;
rtb1.Enabled = false;
rtb1.Multiline = false;
rtb1.ReadOnly = true;

【讨论】:

    猜你喜欢
    • 2020-04-24
    • 1970-01-01
    • 2022-08-17
    • 2022-10-16
    • 2011-04-12
    • 2010-10-23
    • 1970-01-01
    • 1970-01-01
    • 2011-03-18
    相关资源
    最近更新 更多