Ciao a tutti, ho questa classe:
public class TransparentPictureBox : Control
{
private Timer refresher;
private Image _image = null;
public TransparentPictureBox()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true);
refresher = new Timer();
refresher.Tick += new EventHandler(this.TimerOnTick);
refresher.Interval = 50;
refresher.Start();
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
}
}
protected override void OnMove(EventArgs e)
{
base.RecreateHandle();
}
protected override void OnPaint(PaintEventArgs e)
{
if (_image != null)
e.Graphics.DrawImage(_image, (Width / 2) - (_image.Width / 2), (Height / 2) - (_image.Height / 2));
}
protected override void OnPaintBackground(PaintEventArgs e)
{
}
private void TimerOnTick(object source, EventArgs e)
{
base.RecreateHandle();
refresher.Stop();
}
public Image Image
{
get
{
return _image;
}
set
{
_image = value;
base.RecreateHandle();
}
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// TransparentPictureBox
//
this.ResumeLayout(false);
}
}
nella mia Form faccio:
private void Form1_Load(object sender, EventArgs e)
{
TransparentPictureBox a = new TransparentPictureBox();
a.Image = Image.FromFile("C:\\test.bmp");
this.Controls.Add(a);
a.Parent = this;
}
qualcuno saprebbe spiegarmi perchè il metodo OnPaint della mia classe non viene mai eseguito?![]()

Rispondi quotando
