开发者

Using IVMRWindowlessControl to display video in a Winforms Control and allow for full screen toggle

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 switchin开发者_Go百科g 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?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜