Использование IVMRWindowlessControl для отображения видео в элементе управления Winforms и обеспечения полноэкранного переключения - PullRequest
1 голос
/ 16 апреля 2010

Я недавно переключился с использования интерфейса IVideoWindow на IVMRWindowlessControl в моем пользовательском элементе управления Winforms для отображения видео.

Причиной этого было включение возможностей масштабирования видео в элементе управления.
Однако при переключении я обнаружил, что режим FullScreen из IVideoWindow недоступен, и в настоящее время я пытаюсь повторить это с помощью метода SetVideoWindow ().

Я обнаружил, что размер моего видео в моем элементе управления имеет такое же разрешение, что и у экрана, однако я не могу заставить элемент управления располагаться в верхней / левой части экрана и становиться самым верхним окном.

Любые идеи о том, как этого добиться, так как IVideoWindow :: put_FullScreenMode только что сделал все это для вас?

1 Ответ

1 голос
/ 19 апреля 2010

Решил проблему FullScreen, разместив элемент управления видео в новой форме, размер которой я изменил до размера текущего экрана, затем обработал нажатие клавиши «Выход» в форме, чтобы переключиться обратно к видео нормального размера. Вот выдержка из кода: -

Пользователи

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