Problem wygląda tak, że wyświetlam sobie obraz z kamery przy pomocy biblioteki EmguCV (OpenCV) w taki oto sposób:
Capture camera = new Capture(0);
Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
{
pictureBox1.Image = camera.QueryFrame().Resize(screenWidth, screenHeight, Emgu.CV.CvEnum.INTER.CV_INTER_AREA).ToBitmap();
});
Czyli wyświetlam obraz na pictureBox'ie, teraz chcę nałożyć na to przeźroczyste button'y, ale niestety muszę stworzyć w tym celu własną klasę (innej możliwości nie znalazłem, ogólnie właściwość "transparent" coś nawala w C#):
using System;
using System.Windows.Forms;
using System.Drawing;
namespace CouchPotato
{
public class ImageButton : Control, IButtonControl
{
private DialogResult myDialogResult;
private Object obj;
private int number;
public ImageButton()
{
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.Opaque, true);
SetStyle(ControlStyles.ResizeRedraw, true);
this.BackColor = Color.Transparent;
}
public void AddImage(Object o, int n)
{
obj = o;
number = n;
}
protected override void OnPaint(PaintEventArgs pevent)
{
base.OnPaint(pevent);
if (number == 200)
{
if (obj != null)
{
pevent.Graphics.DrawImage((Image)obj, 0, 0, 200, 200);
}
}
else if (number == 150)
{
if (obj != null)
{
pevent.Graphics.DrawImage((Image)obj, 0, 0, 150, 150);
}
}
else
{
if (obj != null)
{
pevent.Graphics.DrawImage((Image)obj, 0, 0, 120, 120);
}
}
}
protected override CreateParams CreateParams
{
get
{
const int WS_EX_TRANSPARENT = 0x20;
CreateParams cp = base.CreateParams;
cp.ExStyle |= WS_EX_TRANSPARENT;
return cp;
}
}
public DialogResult DialogResult
{
get
{
return this.myDialogResult;
}
set
{
if (Enum.IsDefined(typeof(DialogResult), value))
{
this.myDialogResult = value;
}
}
}
public void NotifyDefault(bool value) { }
public void PerformClick() { }
}
}
Tworzę obiekty mojej klasy, w main'ie układ je odpowiednio na ekranie, przy pomocy Location, rysuje obrazek na button'ie metodą OnPaint.
Problem wygląda tak, że abym mógł widzieć buttony nałożone na obraz z kamery muszę ciągle odświeżać buttony w pętli wyświetlającej obraz, w przeciwnym wypadku obrazki idą pod obraz z kamery (całe button'y?). Jeżeli metodą OnPaint rysuję po button'ie to znaczy, że cały button (chyba) chowa się pod obraz (a nie tylko obrazek button'a). Jak położe na formę zwykły button w postaci standardowego komponentu to jest on zawsze na wierzchu.
Umiał by ktoś pomóc w tej kwestii?