如何使ListBox中的某些项目变为粗体?

Mar*_*oms 14 .net c# listbox visual-studio

在Visual c#Express Edition中,是否可以在ListBox中创建一些(但不是全部)项目?我在API中找不到任何类型的选项.

Min*_*ras 30

您需要将列表框的DrawMode更改为DrawMode.OwnerDrawFixed.在msdn上查看这些文章:
DrawMode Enumeration
ListBox.DrawItem Event
Graphics.DrawString Method

另请参阅msdn论坛上的这个问题:
关于ListBox项目的问题

一个简单的例子(两个项目 - 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();
    }
 }
Run Code Online (Sandbox Code Playgroud)