C# 标签样式粗体,同时斜体

C# 标签样式粗体,同时斜体,c#,winforms,C#,Winforms,试试这个 if (Convert.ToString( checkedListBox1.SelectedItem )== "Bold") { label1.Font = new Font(label1.Font, FontStyle.Bold); } else if(Convert.ToString( checkedListBox1.SelectedItem )== "Italic") { label1.Font =

试试这个

if (Convert.ToString( checkedListBox1.SelectedItem )== "Bold")           
{
    label1.Font = new Font(label1.Font, FontStyle.Bold);           
}          
else if(Convert.ToString( checkedListBox1.SelectedItem )== "Italic")
{
    label1.Font = new Font(label1.Font, FontStyle.Italic);
}
else if (Convert.ToString(checkedListBox1.SelectedItem) == "UnderLine")
{
    label1.Font = new Font(label1.Font, FontStyle.Underline);
}
更新:
这仅适用于Webapplication

每次传递
label1.Font.Style
,并使用它添加当前样式:

if (Convert.ToString(checkedListBox1.SelectedItem) == "Bold")
    {
        label1.Font.Bold = true;
    }
    else if (Convert.ToString(checkedListBox1.SelectedItem) == "Italic")
    {
        label1.Font.Italic = true;
    }
    else if (Convert.ToString(checkedListBox1.SelectedItem) == "UnderLine")
    {
        label1.Font.Underline = true;
    }
以下是完整的代码:

label1.Font = new Font(label1.Font, label1.Font.Style | FontStyle.Bold);

那么问题是什么呢?windows或asp.net您使用的是哪一种windows,它可以工作,但是当我更改选择索引时,fontstyle会更改,我希望以前更改的字体保持存储状态。就像在word中一样,我们可以同时设置字体的粗体和斜体。我想要这样的代码,如果我更改了所选的值,前一个值将保留在其中,除非我在复选框列表中取消选择它。我们可以同时选择多个值。您在哪里执行此条件?你把它叫做checklistBox事件吗?或例如,无法指定“System.Drawing.Font.Bold”按钮,它是只读的不工作错误提供错误属性或索引器“System.Drawing.Font.Bold”无法分配给--它是只读的。我的代码正在工作,但如果选择了一个值,我希望像ms word一样输出。如果条件编译器始终搜索一个新值并删除以前的字体样式,则其他值不会更改。抱歉,我在想它的Web解决方案。我正在使用窗口应用程序
if (Convert.ToString(checkedListBox1.SelectedItem) == "Bold")
            {
                label1.Font = new Font(label1.Font, label1.Font.Style | FontStyle.Bold);
            }
            else if (Convert.ToString(checkedListBox1.SelectedItem) == "Italic")
            {
                label1.Font = new Font(label1.Font, label1.Font.Style | FontStyle.Italic);
            }
            else if (Convert.ToString(checkedListBox1.SelectedItem) == "UnderLine")
            {
                label1.Font = new Font(label1.Font, label1.Font.Style | FontStyle.Underline);
            }