How to set different colors for items of NListBox


Author
Message
Partho Sarathi
Partho Sarathi
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)
Group: Forum Members
Posts: 9, Visits: 1
How do I set different color background/foreground for items? From what I can understand, this will require writing a custom renderer. I tried to extend NListBoxRenderer but a lot of it's members seem to be Internal. All I need is to be able to change the foreground and background colors for individual items. Can this be done easily?
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K
Hi Partho,

Yes you need to extend NListBoxRenderer.

To change the back color you need to override DrawItemBackground method, and to change the fore color you just need to change Palette.WindowText and Palette.HighlightText.

Here is an example implementation of the DrawItemBackground method:


public override void DrawItemBackground(Graphics g, NListBoxItem item)
{
if (m_List.CurrentSkin != null)
base.DrawItemBackground(g, item);

if (!m_List.Enabled)
return;



if (item.ListBox.SelectedItem == item)
{
base.DrawItemBackground(g, item);
}
else
{
if (m_List.ColumnOnLeft)
{
DrawColumn(g, item);
}

//Here you can use an item.Tag property to provide the desired color instead of the index.
if (item.Index == 1)
{
m_Brush.Color = Color.Red;
}
else
{
m_Brush.Color = m_Palette.Window;
}
g.FillRectangle(m_Brush, m_TextRect);
}
}


Best Regards,
Nevron Support Team


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search