如何更改列表框中所选项目的颜色? [英] How to change color of selected item in ListBox?

查看:42
本文介绍了如何更改列表框中所选项目的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含某些项目的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";

这篇关于如何更改列表框中所选项目的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆