Is it possible to draw a line as shown in the pic on a single form The line in the image is drawn on a second form which is transparent so form1 is visible.
As indicated, it turns on the WS_EX_TRANSPARENT window style. With this style set, Windows ensures that all windows "below" the window get painted first and the transparent window last.
Drawing on[/underneath!] Controls
Robs Pierre
So why does my line control cover the listbox
hemo
using System;
using System.Drawing;
using System.Windows.Forms;
public class Line : Control {
protected override CreateParams CreateParams {
get {
// Turn on the WS_EX_TRANSPARENT style
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
}
}
protected override void OnPaintBackground(PaintEventArgs pevent) {
// Do *not* paint the background
}
protected override void OnPaint(PaintEventArgs e) {
// Draw the line, just a demo here:
e.Graphics.DrawLine(Pens.Black, 0, 0, this.Width, this.Height);
base.OnPaint(e);
}
}
If you animate the line in any way, you'll need to invalidate the control's Parent so the background is redrawn correctly.
Jafar Bhatti
Nodnarb501
Neil Ault
Jesper Ekenberg
David Hanak
Robert G Lewis
Jayakumar A