Groups | Blog | Home
all groups > c# > march 2007 >

c# : listbox problem


ClayB
3/13/2007 4:46:44 PM
One way to do this is to set
this.listBox1.DrawMode = DrawMode.OwnerDrawFixed;
and use the DrawItem ebvent to draw the contents of the listbox
yourself.


private Rectangle lastRectangle = Rectangle.Empty;
private void listBox1_DrawItem(object sender,
DrawItemEventArgs e)
{
if ((e.State & DrawItemState.Selected) != 0)
{
e.Graphics.FillRectangle(Brushes.AliceBlue, e.Bounds);
}

e.Graphics.DrawString(listBox1.GetItemText(listBox1.Items[e.Index]),
listBox1.Font, Brushes.Black, e.Bounds.Location);

if (!lastRectangle.IsEmpty)
{
this.listBox1.Invalidate(lastRectangle);
lastRectangle = Rectangle.Empty;
this.listBox1.Update();
}
lastRectangle = e.Bounds;
}
===============
Clay Burch
Syncfusion, Inc.

bla
3/13/2007 11:23:43 PM
AddThis Social Bookmark Button