【问题标题】:Overlay Picturebox (or image) on top of AxWindowsMediaPlayer在 AxWindowsMediaPlayer 上覆盖 Picturebox(或图像)
【发布时间】:2017-07-08 03:48:43
【问题描述】:

我试图在 AxWindowsMediaPlayer 控件上覆盖一个图片框,但是一旦视频开始播放,视频就会被推到前面。或者失败了,我可以让图片框坐在上面,但它从来没有透明的背景。它似乎继承了表单背景颜色,因此视频不会显示在图片框下方。

我在 MediaPlayer 上使用以下属性

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

我尝试将图片框的背景颜色设置为透明,尝试设置其父级和媒体播放器父级。我已经尝试将它添加到媒体播放器控件中,但都失败了。

我似乎没有通过 Google 找到解决方案,而且我宁愿不必使用外部库,但如果这是最好的解决方案,那我就可以了。

谢谢

【问题讨论】:

    标签: c# winforms axwindowsmediaplayer


    【解决方案1】:

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

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

    完成此操作后,您可以覆盖具有部分透明背景的 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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-01-02
      • 1970-01-01
      • 2011-08-01
      • 1970-01-01
      • 2015-05-15
      • 2023-04-02
      • 2013-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多