Salut.. c'est plus simple avec un Control qu'un UserControl :
public partial class Form1 : Form
{
private class MyControl : Control
{
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; // WS_EX_TRANSPARENT;
return cp;
}
}
protected override void OnPaintBackground( PaintEventArgs args )
{
//base.OnPaintBackground( args );
Graphics g = args.Graphics;
Rectangle r = this.ClientRectangle;
g.DrawRectangle( Pens.Black, new Rectangle( 0, 0, r.Width - 1, r.Height - 1 ) );
g.FillRectangle( new SolidBrush( Color.FromArgb( 128, Color.Red ) ), r );
}
}
public Form1( )
{
InitializeComponent( );
PictureBox pb = new PictureBox( );
pb.Size = new Size( 100, 100 );
pb.BackColor = Color.AliceBlue;
pb.BorderStyle = BorderStyle.FixedSingle;
MyControl mc = new MyControl( );
mc.Size = new Size( 100, 100 );
mc.Location = new Point( 50, 50 );
this.Controls.AddRange( new Control[ ] { mc, pb } );
}
}