473,769 Members | 6,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 29319
On Apr 4, 5:47*pm, CSharper <cshar...@gmx.c omwrote:
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.c omschreef in bericht
news:41******** *************** ***********@a22 g2000hsc.google groups.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 PopulateListBox es()
{

Updating = true;

areaListBox.Ite ms.Add(new AreaStyle("Keyw ords", Color.Black,
Color.White, "Standard") );

areaListBox.Ite ms.Add(new AreaStyle("Comm ents", Color.Green,
Color.White, "Standard") );

areaListBox.Ite ms.Add(new AreaStyle("Numb ers", Color.Navy, Color.Yellow,
"Bold"));

areaListBox.Ite ms.Add(new AreaStyle("Stri ngs", Color.Maroon,
Color.White, "Standard") );

areaListBox.Ite ms.Add(new AreaStyle("Loca l variables", Color.OrangeRed ,
Color.White, "Bold"));

areaListBox.Ite ms.Add(new AreaStyle("Bool ean operators", Color.Black,
Color.White, "Bold"));

areaListBox.Ite ms.Add(new AreaStyle("Sign als", Color.CadetBlue ,
Color.White, "Bold"));

}

private void areaListBox_Dra wItem(object sender, DrawItemEventAr gs 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.Bou nds.X, e.Bounds.Y,
e.Bounds.Width - 1, e.Bounds.Height - 1);

using(Brush backBrush = new SolidBrush(styl e.BackColor))

{

// Paint the item background in the wanted color

e.Graphics.Fill Rectangle(backB rush, SelRect);

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

{

if(e.State == DrawItemState.S elected)

{

// 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.Draw Rectangle(p, SelRect);

}

e.DrawFocusRect angle();

using(Brush brush = new SolidBrush(styl e.ForeColor))

{

using(Font font = new Font(list.Font,
GetFonstyleFrom Name(style.Font Style)))

{

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

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

}

}

}

private void areaListBox_Mea sureItem(object sender, MeasureItemEven tArgs e)

{

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

e.ItemHeight += 2;

}

bart
Apr 4 '08 #3
"CSharper" <cs******@gmx.c omwrote in message
news:41******** *************** ***********@a22 g2000hsc.google groups.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
11268
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 change color when any of the three are hovered over. I would prefer to do this with pure CSS if possible, but if Javascript is the only way...so be it. --
1
2554
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
13495
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
2385
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
1330
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
1291
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 that. Thanks, TonyVal
6
3953
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 change color when i click on this row and change to third color and ,this color stay when my mouse is out.please help
0
1471
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
2718
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 mouseout correctly only to make it change color to black once I click on it. Could someone help? Thansk nma <td width="<?php echo ($cellwidth); ?>" height="17" bgcolor="#00ff00" onMouseOver="this.style.background ='red'"
3
2002
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" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="refresh" content="refreshrate"> <title>Insert title here</title> <link rel="stylesheet"...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10045
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.