How can I make some items in a ListBox bold?(如何使 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.
推荐答案
需要将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 中的某些项目变为粗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使 ListBox 中的某些项目变为粗体?
基础教程推荐
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
