473,395 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Selectively change the color of an Item in a listbox

Is it possible to selectivly change the color of an item in text. I
saw ForeColor option, but it changes the color of all the items. If it
is not possible, is there any other control list listbox where we can
see more than one item and change the color during run time.
Thanks.
Apr 4 '08 #1
3 29284
On Apr 4, 5:47*pm, CSharper <cshar...@gmx.comwrote:
Is it possible to selectivly change the color of an item in text. I
saw ForeColor option, but it changes the color of all the items. If it
is not possible, is there any other control list listbox where we can
see more than one item and change the color during run time.
Thanks.
IIRC this is not allowed.

You would have to implement it your self.

Do a search by owned draw control in opennetcf.org to see an example.
Even as it's for the CF the same idea applies
Apr 4 '08 #2

"CSharper" <cs******@gmx.comschreef in bericht
news:41**********************************@a22g2000 hsc.googlegroups.com...
Is it possible to selectivly change the color of an item in text. I
saw ForeColor option, but it changes the color of all the items. If it
is not possible, is there any other control list listbox where we can
see more than one item and change the color during run time.
Thanks.


i think this should do,

private void PopulateListBoxes()
{

Updating = true;

areaListBox.Items.Add(new AreaStyle("Keywords", Color.Black,
Color.White, "Standard"));

areaListBox.Items.Add(new AreaStyle("Comments", Color.Green,
Color.White, "Standard"));

areaListBox.Items.Add(new AreaStyle("Numbers", Color.Navy, Color.Yellow,
"Bold"));

areaListBox.Items.Add(new AreaStyle("Strings", Color.Maroon,
Color.White, "Standard"));

areaListBox.Items.Add(new AreaStyle("Local variables", Color.OrangeRed,
Color.White, "Bold"));

areaListBox.Items.Add(new AreaStyle("Boolean operators", Color.Black,
Color.White, "Bold"));

areaListBox.Items.Add(new AreaStyle("Signals", Color.CadetBlue,
Color.White, "Bold"));

}

private void areaListBox_DrawItem(object sender, DrawItemEventArgs e)
{

ListBox list = (ListBox)sender;

AreaStyle style = (AreaStyle)list.Items[e.Index];
Color foreColor = Color.Empty;

Color backColor = Color.Empty;

// Get the Bounding rectangle for a selected item

Rectangle SelRect = new Rectangle(e.Bounds.X, e.Bounds.Y,
e.Bounds.Width - 1, e.Bounds.Height - 1);

using(Brush backBrush = new SolidBrush(style.BackColor))

{

// Paint the item background in the wanted color

e.Graphics.FillRectangle(backBrush, SelRect);

}
using (Pen p = new Pen(Color.Empty))

{

if(e.State == DrawItemState.Selected)

{

// Set the pen color

p.Color = Color.Black;

}

else

{

// Set the pen color

p.Color = list.BackColor;

}

// Draw the selection rectangle in either black or the lisbox
backcolor to hide it

e.Graphics.DrawRectangle(p, SelRect);

}

e.DrawFocusRectangle();

using(Brush brush = new SolidBrush(style.ForeColor))

{

using(Font font = new Font(list.Font,
GetFonstyleFromName(style.FontStyle)))

{

string text = list.Items[e.Index].ToString();

e.Graphics.DrawString(text, font, brush, e.Bounds.X, e.Bounds.Y
+ 1);

}

}

}

private void areaListBox_MeasureItem(object sender, MeasureItemEventArgs e)

{

// Increase slightly to create some room for the selection rectangle

e.ItemHeight += 2;

}

bart
Apr 4 '08 #3
"CSharper" <cs******@gmx.comwrote in message
news:41**********************************@a22g2000 hsc.googlegroups.com...
Is it possible to selectivly change the color of an item in text. I
saw ForeColor option, but it changes the color of all the items. If it
is not possible, is there any other control list listbox where we can
see more than one item and change the color during run time.
Thanks.
One option is to use a ListView instead. It allows the color to be set
indvidually for each item.
/claes
Apr 7 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sugapablo | last post by:
Can anyone help me out with some code to change three table cells (<td>) when one is hovered over? I have a calendar grid where each day is made up of three table cells and I want all three to...
1
by: Robbo | last post by:
Hello, I created a datagrid with a few hyperlink columns.. How do i change the color of the hyperlink itself? BLUE is a bit bad on my datagrid color scheme. Thanks, Rob
2
by: HS1 | last post by:
Hello all Do you know how to change color of a button when the mouse is over it (like a button in manu bar can change its color in a website) in VB.net Thank you S.Hoa
3
by: Mamatha | last post by:
Hi I want to change the color of icon,How it can be opened? and how can i change color. If any one knows please let me know Thanks in advance. Mamatha
1
by: Vd | last post by:
How do I change color of the tab. I have changed the color, but when I run the application the color is still using the original color which is the control color.
2
by: TonyVal - MSDN News | last post by:
Hi All, Anyone know how to change color for a 3D button like this button control does? http://www.econtechvn.com/en/aquabutton_detail.htm I see it is really cool. But, don't know how to do...
6
by: sr | last post by:
please help i have problem: I know how to change color row in table when my mouse is over on this row and change color to another color when my mouse is out from this row. but i dont know how to...
0
by: write2jagdeep | last post by:
i Want to change color of text item when got focus in forms builber d2k and revert that color when lost focus. Pls anser it urgently.
3
by: nma | last post by:
Hi How do I make the cell change color to 'black' after I click on it. The cell will remain black color until I click another cell which will also change to black. I can do the mouseover and...
3
by: prabhuaradhan | last post by:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.