在 Visual c# Express Edition 中,是否可以将 ListBox 中的某些(但不是全部)项目设为粗体?我在 API 中找不到任何类型的选项。
最佳答案
您需要将列表框的 DrawMode 更改为 DrawMode.OwnerDrawFixed。在 msdn 上查看这些文章:
DrawMode Enumeration
ListBox.DrawItem Event
Graphics.DrawString Method
另请参阅 msdn 论坛上的这个问题:
Question on ListBox items
一个简单的例子(两个项目 - Black-Arial-10-Bold):
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ListBox1.Items.AddRange(new Object[] { "First Item", "Second Item"});
ListBox1.DrawMode = DrawMode.OwnerDrawFixed;
}
private void ListBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
e.Graphics.DrawString(ListBox1.Items[e.Index].ToString(), new Font("Arial", 10, FontStyle.Bold), Brushes.Black, e.Bounds);
e.DrawFocusRectangle();
}
}
关于c# - 如何使 ListBox 中的某些项目变为粗体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/327310/