2010-04-16 63 views
1

我最近剛從IVideoWindow接口IVMRWindowlessControl在我的自定義的WinForms切換控制顯示視頻。使用IVMRWindowlessControl顯示在一個WinForms控制視頻,並允許全屏切換

這樣做的原因是爲了讓在控制範圍之內的視頻縮放功能。
但是在切換時,我發現IVideoWindow的FullScreen模式不可用,我目前正在嘗試使用SetVideoWindow()方法來複制此模式。

我發現我將控件中的視頻大小設置爲與屏幕相同的分辨率,但我無法將控件定位到屏幕的頂部/左側併成爲最頂層的窗口。

就如何實現這一目標,因爲IVideoWindow任何想法:: put_FullScreenMode只是做了這一切嗎?

回答

1

解決了FullScreen問題,通過將視頻控件託管爲全新的形式,並將其調整爲當前屏幕的大小,然後在窗體中處理「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; 
     } 
    } 
相關問題