如何更改列表框中所选项目的颜色?

问题描述:

我有一个包含某些项目的ListBox控件,我想更改所选项目的颜色...如何在C#(WinForms)中做到这一点?请帮我:)

I have a ListBox control with some items and I want to change color of selected item... How can I do it in C# (WinForms)? Help me please :)

这是将红色设置为选定的ASP.NET ListBox项的方法:

This is how you can set, say Red color, to the selected ASP.NET ListBox items:

 <asp:ListBox runat="server" ID="ListBox1">
    <asp:ListItem Text="Text1"></asp:ListItem>
    <asp:ListItem Text="Text2"></asp:ListItem>
</asp:ListBox>


        if(ListBox1.SelectedItem != null)
            ListBox1.SelectedItem.Attributes["style"] = "color:red";