使用 IVMRWindowlessControl 在 Winforms 控件中显示视频并允许全屏切换

发布于 2024-08-29 00:23:18 字数 329 浏览 7 评论 0原文

我最近在自定义 Winforms 控件中从使用 IVideoWindow 接口切换到使用 IVMRWindowlessControl 来显示视频。

这样做的原因是为了允许控件内的视频具有缩放功能。
然而,在切换时,我发现 IVideoWindow 的全屏模式不可用,我目前正在尝试使用 SetVideoWindow() 方法复制此模式。

我发现我将控件中的视频大小调整为与屏幕的分辨率相同,但是我无法让控件将其自身定位到屏幕的顶部/左侧并成为最顶部的窗口。

既然 IVideoWindow::put_FullScreenMode 已经为您完成了这一切,那么关于如何实现这一点有什么想法吗?

I've recently switched from using the IVideoWindow interface to IVMRWindowlessControl in my custom Winforms control to display video.

The reason for this was to allow zoom capabilities on the video within the control.
However in switching over, I've found that the FullScreen mode from IVideoWindow is not available and I am currently trying to replicate this using the SetVideoWindow() method.

I'm finding that I size the video in my control to be at the same resolution as the screen however I can't get the control to position itself to the top/left of the screen and become the top most window.

Any ideas on how to achieve this since the IVideoWindow::put_FullScreenMode just did it all for you?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

皇甫轩 2024-09-05 00:23:18

通过以新的形式托管视频控件来解决全屏问题,我将其大小调整为当前屏幕的大小,然后处理形式中的“Escape”按键,以切换回正常大小的视频。以下是代码摘录:-

成员

    private Rectangle fullScreenRectangle;
    private bool fullScreen;
    private Form fullScreenForm;
    private Control fullScreenParent;

切换全屏代码

    /// <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;
        }
    }

Resolved the FullScreen problem by hosting the video control in a fresh form which I resized to the size of the current screen, then handled the 'Escape' key press in the form, to toggle back to the normal size video. Here's an extract of the code:-

Members

    private Rectangle fullScreenRectangle;
    private bool fullScreen;
    private Form fullScreenForm;
    private Control fullScreenParent;

Toggle FullScreen code

    /// <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;
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文