Transparentes Forms.Control schreiben -- Probleme.
-
Hi,
Ich versuche eine Klasse von Windows.Forms.Control abzuleiten, um ein eigenes Control zu erzeugen, das vollständig transparent ist. Dieses möchte ich über andere Controls und Panels legen, um extra-Informationen anzuzeigen. Sozusagen eine transparente Folie, wo man drauf malen kann. Wie beim Overhead-Projektor
Leider werden die unterliegenden Controls nicht mehr gezeichnet, sobald ich meine Folie mit BringToTop() ganz nach oben in der Z-Order bringe.
Der Konstruktor sieht so aus:
... public OverlayPaintControl() { // Enable doubleBuffering this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); this.UpdateStyles(); // Support transparent background SetStyle(ControlStyles.SupportsTransparentBackColor, true); SetStyle(ControlStyles.Selectable, false); this.BackColor = Color.FromArgb(0, 0, 0, 0); } ...
Und wie folgt wollte ich das Control benutzen:
... _overlayControl.Location = new Point(0, 0); _overlayControl.Size = this.Size; _overlayControl.Enabled = false; _overlayControl.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; Controls.Add(_overlayControl); _overlayControl.BringToFront(); ...
Hat jemand eine Ahnung, wie ich am Besten so eine "Folie" bastel?
Vielen Dank und viele Grüße,
Felix
-
Ich habe schonmal festgestellt, dass ich vergessen habe, die CreateParams Property zu überschreiben. Hiermit klappt es, allerdings nur, wenn ich beim OnPaint kein Graphics.Clear aufrufe (was mir dann aber natürlich das alte Bild stehenlässt).
protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x20; return cp; } }
Was kann ich tun? Wie schaffe ich es, dass ich das alte Bild lösche und dennoch transparent bleibe??