我正在尝试将一个图片框叠加在AxWindowsMediaPlayer控件的顶部,但是一旦视频开始播放,视频就会被推到前面。或者失败了,我可以让图片框坐在上面,但它从来没有透明的背景。它似乎继承了表单背景颜色,因此视频不会显示在图片框下方。
我在MediaPlayer上使用以下属性
uiMode = "none";
enableContextMenu = false;
windowlessVideo = true;
我尝试将图片框的BackColor设置为透明,尝试将其父级和媒体播放器设置为父级。我已经尝试将它添加到媒体播放器控件中,但都失败了。
似乎没有我通过谷歌找到的解决方案,我不想使用外部库,但如果这是最好的解决方案,那么我就可以了。
谢谢
答案 0 :(得分:0)
对于任何想要这样做的人来说,这是解决方案。
我创建了一个位于播放视频的表单顶部的表单,并将其颜色透明度键设置为白色,并将窗口背景设置为白色。
执行此操作后,您可以覆盖具有部分透明背景的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);
}
}