Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

How to change ListBox selection background color

private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
    if (e.Index<0) return;
    //if the item state is selected them change the back color 
    if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
        e = new DrawItemEventArgs(e.Graphics, 
                                  e.Font, 
                                  e.Bounds, 
                                  e.Index,
                                  e.State ^ DrawItemState.Selected,
                                  e.ForeColor, 
                                  Color.Yellow);//Choose the color

    // Draw the background of the ListBox control for each item.
    e.DrawBackground();
    // Draw the current item text
    e.Graphics.DrawString(listBox1.Items[e.Index].ToString(),e.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault);
    // If the ListBox has focus, draw a focus rectangle around the selected item.
    e.DrawFocusRectangle();
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: lwjgl fullscreen 
Csharp :: how to use monitor from system.threading in c# 
Csharp :: indexing an array 
Csharp :: c# system cryptography hash string 
Csharp :: asp.net listbox disable selection 
Csharp :: print text c# unity 
Csharp :: get gameobject layermask 
Csharp :: c# check if string contains character multiple times 
Csharp :: how to pass function as paraemter of another function pythpn 
Csharp :: play sound in sequence unity 
Csharp :: autoit console write 
Csharp :: c# insert backslash in string 
Csharp :: car controller unity 
Csharp :: count number of specific characters in string c# 
Csharp :: how to show a first item in a combobox in c# winforms 
Csharp :: instantiate c# 
Csharp :: c# interface property 
Csharp :: value is null to insert in c# 
Csharp :: ado stands for 
Csharp :: static keyword 
Csharp :: c# async task constructor 
Csharp :: how to use date range picker in asp.net C# 
Csharp :: ExpandoObject Add PropertyName and PropertyValue Dynamically 
Csharp :: c# webbrowser upload file 
Csharp :: Go Statement in CSharp 
Csharp :: c# windows forms rtc 
Csharp :: VSIX Project Context Menu 
Csharp :: C# decimal built-in methods 
Csharp :: Toggle value change 
Csharp :: overloading constructors c# 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =