在下拉菜单项C#中使文本变为粗体 [英] Making text bold in dropdown menu item C#
本文介绍了在下拉菜单项C#中使文本变为粗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码,并且我想使选中的项目变为粗体或选中.我的编译器给出一个错误,告诉我它是只读的.这里有什么解决方法吗?
谢谢!
Hi,
i have the following code, and I want to make the selected item bold or checked. My compiler gives an error which tells me it is read-only. Is there some sort of workaround here?
Thanks!
private void addprinter(string printername)
{
ToolStripItem addItem = selectPrinterToolStripMenuItem1.DropDownItems.Add(printername);
addItem.Click += new EventHandler(printerName_Click);
}
private void printerName_Click(object sender, EventArgs e)
{
ToolStripItem item = (ToolStripItem)sender;
SelectedPrinterName = item.Text;
item.Font.Bold = true; // <-- error is here
item.Checked = true; // <--and here
MessageBox.Show(SelectedPrinterName, "SystemInformation #208", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
推荐答案
我不确定该解决方案是否适合您,但是可以使用:
问题是字体内的属性是只读的.解决方案是创建一个新字体,如下所示:
I''m not sure if this solution will work for you, but here goes:
The problem is that the properties inside the Font are read-only. The solution is to create a new font, like this:
btn1.DropDown.Font = new Font(btn1.DropDown.Font, FontStyle.Bold);
来源 [这一个 [ ^ ].您也许可以使用此解决方案中的概念将其应用于您选择的项目.
Source[^]
Another potential way to do this is: This One[^]. You could perhaps use the concepts in this solution to apply against your selected item.
这篇关于在下拉菜单项C#中使文本变为粗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文