I'm trying to overlay a picture box on top of a AxWindowsMediaPlayer control, but as soon as the video starts playing, the video is pushed to the front. Or failing that, I can get the picture box to sit on top, but it never has a transparent background. It seems to inherit the forms background color, so the video will not display beneath the picture box.
I'm using the following properties on the MediaPlayer
uiMode = "none";
enableContextMenu = false;
windowlessVideo = true;
I've tried setting the picture box's BackColor to transparent, tried setting its parent and the media players parent. I've tried adding it to the media player control, all failing.
There doesn't seem to be a solution that I've found via Google, and I'd prefer not to have to use an external library, although if that's the best solution, then I'd be ok with that.
Thank you
For anyone else looking to do this, here is the solution.
I created a Form that sits on top of the form playing the video, and set it's color transparency key to white, and set the window background to white.
After doing that, you can overlay things like picture boxes that have a Png with a partly transparent background and it will render as expected.
This is basically the final piece in the puzzle, from the solution to a similar issue posted here: Draw semi transparent overlay image all over the windows form having some controls
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MyProject
{
public partial class Form2 : Form
{
public Form2(Form formToCover)
{
InitializeComponent();
this.AllowTransparency = true;
this.TransparencyKey = Color.White;
this.BackColor = Color.White;
this.FormBorderStyle = FormBorderStyle.None;
this.ControlBox = false;
this.ShowInTaskbar = false;
this.StartPosition = FormStartPosition.Manual;
this.AutoScaleMode = AutoScaleMode.None;
this.Location = formToCover.PointToScreen(Point.Empty);
this.ClientSize = formToCover.ClientSize;
formToCover.LocationChanged += Cover_LocationChanged;
formToCover.ClientSizeChanged += Cover_ClientSizeChanged;
// Show and focus the form
this.Show(formToCover);
formToCover.Focus();
// Disable Aero transitions, the plexiglass gets too visible
if (Environment.OSVersion.Version.Major >= 6)
{
int value = 1;
DwmSetWindowAttribute(formToCover.Handle, DWMWA_TRANSITIONS_FORCEDISABLED, ref value, 4);
}
}
private void Cover_LocationChanged(object sender, EventArgs e)
{
// Ensure the plexiglass follows the owner
this.Location = this.Owner.PointToScreen(Point.Empty);
}
private void Cover_ClientSizeChanged(object sender, EventArgs e)
{
// Ensure the plexiglass keeps the owner covered
this.ClientSize = this.Owner.ClientSize;
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
// Restore owner
this.Owner.LocationChanged -= Cover_LocationChanged;
this.Owner.ClientSizeChanged -= Cover_ClientSizeChanged;
if (!this.Owner.IsDisposed && Environment.OSVersion.Version.Major >= 6)
{
int value = 1;
DwmSetWindowAttribute(this.Owner.Handle, DWMWA_TRANSITIONS_FORCEDISABLED, ref value, 4);
}
base.OnFormClosing(e);
}
protected override void OnActivated(EventArgs e)
{
// Always keep the owner activated instead
this.BeginInvoke(new Action(() => this.Owner.Activate()));
}
private const int DWMWA_TRANSITIONS_FORCEDISABLED = 3;
[DllImport("dwmapi.dll")]
private static extern int DwmSetWindowAttribute(IntPtr hWnd, int attr, ref int value, int attrLen);
}
}