我最近在自定义Winforms控件中使用IVideoWindow界面切换到IVMRWindowlessControl来显示视频。
原因是允许控件内视频的缩放功能 但是在切换时,我发现IVideoWindow的FullScreen模式不可用,我目前正在尝试使用SetVideoWindow()方法复制它。
我发现我在控件中调整视频的大小与屏幕的分辨率相同但是我无法让控件将自己定位到屏幕的顶部/左侧并成为最顶层的窗口。
自IVideoWindow :: put_FullScreenMode以来,如何实现这一目标的任何想法都为你做了一切?
答案 0 :(得分:1)
通过以新的形式托管视频控件解决了FullScreen问题,我将其调整为当前屏幕的大小,然后按下表单中的“Escape”键,切换回正常大小的视频。这是代码的摘录: -
成员
private Rectangle fullScreenRectangle;
private bool fullScreen;
private Form fullScreenForm;
private Control fullScreenParent;
切换FullScreen代码
/// <summary>
/// Toggle Full Screen Mode
/// </summary>
public bool FullScreen
{
get
{
return this.fullScreen;
}
set
{
this.fullScreen = value;
if (this.fullScreen)
{
// If switch to full screen, save the current size of the control
this.fullScreenRectangle = new Rectangle(this.Location, this.Size);
// Get the current screen resolution and set that to be the control's size
Rectangle screenRect = Screen.GetBounds(this);
// Create a new form on which to host the control whilst we go to full screen mode.
this.fullScreenForm = new Form();
this.fullScreenForm.Location = PointToScreen(new Point(0, 0));
this.fullScreenForm.Size = new Size(screenRect.Width, screenRect.Height);
this.fullScreenForm.BackColor = Color.Black;
this.fullScreenForm.ShowInTaskbar = false;
this.fullScreenForm.ShowIcon = false;
this.fullScreenForm.FormBorderStyle = FormBorderStyle.None;
this.fullScreenForm.KeyPreview = true;
this.fullScreenForm.PreviewKeyDown += new PreviewKeyDownEventHandler(fullScreenForm_PreviewKeyDown);
this.fullScreenParent = this.Parent;
this.fullScreenForm.Controls.Add(this);
this.fullScreenForm.Show();
this.windowlessControl.SetVideoPosition(null, screenRect);
}
else
{
// Revert to the original control size
this.Location = PointToScreen(new Point(this.fullScreenRectangle.Left, this.fullScreenRectangle.Top));
this.Size = new Size(this.fullScreenRectangle.Width, this.fullScreenRectangle.Height);
this.windowlessControl.SetVideoPosition(null, this.fullScreenRectangle);
if (this.fullScreenForm != null)
{
this.fullScreenForm.Controls.Remove(this);
if (this.fullScreenParent != null)
this.Parent = this.fullScreenParent;
this.fullScreenForm.PreviewKeyDown -= new PreviewKeyDownEventHandler(fullScreenForm_PreviewKeyDown);
this.fullScreenForm.Close();
}
}
}
}
void fullScreenForm_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
var viewer = this.Controls[0] as ViewerControl;
if (viewer != null)
viewer.FullScreen = false;
}
}