O
Olo
Hi,
I have to write transparent control - simple red rectangle. When I mouse
move control should change position(left and top). The problem is when
red rectangle is moving over other controls such Buttons, PictureBoxes
it flicker.
Below is code of rectangle control :
public class TransRectangle : System.Windows.Forms.UserControl
{
public TransRectangle()
{
InitializeComponent();
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp=base.CreateParams;
cp.ExStyle|=0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}
//Override the OnPaintBackground event. This is ecessary //to
prevent the background to be painted.
protected override void OnPaintBackground(PaintEventArgs e)
{
// do nothing
}
protected void InvalidateEx()
{
if(Parent==null)
return;
Rectangle rc=new Rectangle(this.Location,this.Size);
Parent.Invalidate(rc,true);
}
protected override void OnMove(EventArgs e)
{
this.InvalidateEx();
Graphics g = this.CreateGraphics();
g.DrawRectangle(Pens.Red, 0, 0, this.Width - 1,
this.Height -1);
g.Dispose();
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawRectangle(Pens.Red, 0, 0, this.Width - 1,
this.Height -1);
}
protected override void OnMouseMove(MouseEventArgs e)
{
this.Left += e.X;
this.Top += e.Y;
base.OnMouseMove (e);
}
public void pInvalidate()
{
this.InvalidateEx();
}
}
Regards,
Olo
I have to write transparent control - simple red rectangle. When I mouse
move control should change position(left and top). The problem is when
red rectangle is moving over other controls such Buttons, PictureBoxes
it flicker.
Below is code of rectangle control :
public class TransRectangle : System.Windows.Forms.UserControl
{
public TransRectangle()
{
InitializeComponent();
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp=base.CreateParams;
cp.ExStyle|=0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}
//Override the OnPaintBackground event. This is ecessary //to
prevent the background to be painted.
protected override void OnPaintBackground(PaintEventArgs e)
{
// do nothing
}
protected void InvalidateEx()
{
if(Parent==null)
return;
Rectangle rc=new Rectangle(this.Location,this.Size);
Parent.Invalidate(rc,true);
}
protected override void OnMove(EventArgs e)
{
this.InvalidateEx();
Graphics g = this.CreateGraphics();
g.DrawRectangle(Pens.Red, 0, 0, this.Width - 1,
this.Height -1);
g.Dispose();
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawRectangle(Pens.Red, 0, 0, this.Width - 1,
this.Height -1);
}
protected override void OnMouseMove(MouseEventArgs e)
{
this.Left += e.X;
this.Top += e.Y;
base.OnMouseMove (e);
}
public void pInvalidate()
{
this.InvalidateEx();
}
}
Regards,
Olo