listbox problem

  • Thread starter Thread starter bla
  • Start date Start date
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top