本文介绍了如何使ListBox中的某些项目变为粗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在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.
推荐答案
您需要将列表框的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论坛上查看此问题:
对ListBox项的疑问
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中的某些项目变为粗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!