How to display a line, over a control?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi,
how to draw a line above a ListBox in a form. Currently I can draw the
line(onPain event), but the Listbox hides it and only some part of the line
gets displayed.

i have used the 'send to back' property to push the listbox to the back and
then draw the line. but it failed and most part of the line is hidden behind
the listbox.

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)...End Sub. I
have written code in this event. then tried in activate/deactivate events.
still results are the same.

kindly post ur valuable tips,
thanks & regards,
hari
 
First you need to make the list box owner drawn.

Then you need override the DrawItem event and make sure you draw each item
in the list box.

Finally you can draw a line over the list box (or each item if you wish) by
drawing a line after the other drawing methods have been called.

EG:
private void listBox1_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{


if ( e.Index >= 0 )
{
// clear the box
e.DrawBackground();
e.DrawFocusRectangle();
e.Graphics.DrawRectangle( new Pen( Color.LightGray, 0.1F ),
e.Bounds ); // item border

// draw the title
e.Graphics.DrawString( listBox1.Items[e.Index].Text,
new Font("Tahoma", 10 ),
new SolidBrush(Color.Black),
e.Bounds.Left + 2,
e.Bounds.Top + 2);

// draw line here across each item
//e.Graphics.DrawLine (....);
}
}
 
Back
Top