"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