在 AxWindowsMediaPlayer 上叠加 Picturebox(或图像)

Overlay Picturebox (or image) on top of AxWindowsMediaPlayer

我试图在 AxWindowsMediaPlayer 控件上叠加一个图片框,但视频一开始播放,视频就被推到最前面。或者做不到这一点,我可以让图片框位于顶部,但它永远不会有透明背景。好像继承了窗体的背景色,所以视频不会显示在图片框下面。

我在 MediaPlayer 上使用以下属性

uiMode = "none";
enableContextMenu = false;
windowlessVideo = true;

我试过将图片框的BackColor 设置为透明,尝试设置它的父级和媒体播放器的父级。我试过将它添加到媒体播放器控件,都失败了。

似乎没有我通过 Google 找到的解决方案,我宁愿不必使用外部库,但如果那是最好的解决方案,那么我'没关系。

谢谢

对于其他想要这样做的人,这里是解决方案。

我创建了一个位于播放视频的窗体之上的窗体,并将其颜色透明度键设置为白色,并将 window 背景设置为白色。

这样做之后,您可以叠加具有部分透明背景的 Png 的图片框之类的东西,它会按预期呈现。

这基本上是拼图中的最后一块,从这里发布的类似问题的解决方案: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);
    }
}