E
eric
Hello,
I am realizing an application containing a display with two layers.
The first layer is the background layer
and it contains an image refreshed very often (more than once a
second) while the second layer is the transparent
foreground layer. I can draw some geometrical forms on it using
Grahics.Draw(...) methods.
My problem is the following, each time I refresh the image on the
first layer (with layer.BackgroundImage), the
drawing done on the transparent layer disappear.
Is there a solution to have independent refreshing layer ?
Here is my code :
*******
public partial class Form1 : Form
{
private int index = 0;
public Form1()
{
InitializeComponent();
layerImage.Parent = panel1; //layerImage is a classical
panel
layerDrawing.Parent = panel1; //layerDrawing is a
transpanel
layerDrawing.BringToFront(); //Bring it to the foreground
this.timer1.Start();
}
private void checkBox1_CheckedChanged(object sender, EventArgs
e)
{
if (checkBox1.Checked)
{
Graphics g = layerDrawing.CreateGraphics();
g.DrawLine(new Pen(Color.Red), layerDrawing.Location,
new Point(layerDrawing.Location.X + layerDrawing.Width,
layerDrawing.Location.Y + layerDrawing.Height));
g.DrawLine(new Pen(Color.Red), new
Point(layerDrawing.Location.X, layerDrawing.Location.Y +
layerDrawing.Height), new Point(layerDrawing.Location.X +
layerDrawing.Width, layerDrawing.Location.Y));
}
else
layerDrawing.Invalidate();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (index == 4)
index = 0;
layerImage.BackgroundImage = new
Bitmap(Environment.CurrentDirectory + @"\..\..\image\Image" + index++
+ ".jpg");
}
}
*********
*********
public class TransPanel : Panel
{
public TransPanel()
{
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}
protected override void OnPaintBackground(PaintEventArgs
pevent)
{
//do not allow the background to be painted
}
}
*********
I am realizing an application containing a display with two layers.
The first layer is the background layer
and it contains an image refreshed very often (more than once a
second) while the second layer is the transparent
foreground layer. I can draw some geometrical forms on it using
Grahics.Draw(...) methods.
My problem is the following, each time I refresh the image on the
first layer (with layer.BackgroundImage), the
drawing done on the transparent layer disappear.
Is there a solution to have independent refreshing layer ?
Here is my code :
*******
public partial class Form1 : Form
{
private int index = 0;
public Form1()
{
InitializeComponent();
layerImage.Parent = panel1; //layerImage is a classical
panel
layerDrawing.Parent = panel1; //layerDrawing is a
transpanel
layerDrawing.BringToFront(); //Bring it to the foreground
this.timer1.Start();
}
private void checkBox1_CheckedChanged(object sender, EventArgs
e)
{
if (checkBox1.Checked)
{
Graphics g = layerDrawing.CreateGraphics();
g.DrawLine(new Pen(Color.Red), layerDrawing.Location,
new Point(layerDrawing.Location.X + layerDrawing.Width,
layerDrawing.Location.Y + layerDrawing.Height));
g.DrawLine(new Pen(Color.Red), new
Point(layerDrawing.Location.X, layerDrawing.Location.Y +
layerDrawing.Height), new Point(layerDrawing.Location.X +
layerDrawing.Width, layerDrawing.Location.Y));
}
else
layerDrawing.Invalidate();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (index == 4)
index = 0;
layerImage.BackgroundImage = new
Bitmap(Environment.CurrentDirectory + @"\..\..\image\Image" + index++
+ ".jpg");
}
}
*********
*********
public class TransPanel : Panel
{
public TransPanel()
{
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}
protected override void OnPaintBackground(PaintEventArgs
pevent)
{
//do not allow the background to be painted
}
}
*********