问题描述
在 Visual c# Express Edition 中,是否可以将 ListBox 中的某些(但不是全部)项目设为粗体?我在 API 中找不到任何类型的选项.
In Visual c# Express Edition, is it possible to make some (but not all) items in a ListBox bold? I can't find any sort of option for this in the API.
推荐答案
需要将listbox的DrawMode改为DrawMode.OwnerDrawFixed.查看 msdn 上的这些文章:
DrawMode 枚举
ListBox.DrawItem 事件
Graphics.DrawString 方法
You need to change listbox's DrawMode to DrawMode.OwnerDrawFixed. Check out these articles on msdn:
DrawMode Enumeration
ListBox.DrawItem Event
Graphics.DrawString Method
在msdn论坛上也看看这个问题:
关于列表框项目的问题一个>
Also look at this question on msdn forums:
Question on ListBox items
一个简单的例子(两个项目 - Black-Arial-10-Bold):
A simple example (both 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();
}
}
这篇关于如何使 ListBox 中的某些项目变为粗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!