c# 控件多屏显示全屏功能

来源:互联网 发布:流程图绘制软件 编辑:程序博客网 时间:2024/05/17 16:16

   工作中做了个播放的自定义控件,但程序在多屏幕显示器上运行时,全屏后总在主显示器上,查了些资料,做以下总结避免以后走弯路


            if (m_FullScreen)
            {
                MenuItem_Fullscreen.Text = "退出全屏";
                if (m_FullSreenSingle)      //因为是多播放窗口控件,此处做了其中一个全屏的控制
                {
                    MenuItem_FullscreenSingle.Visible = false;
                    OldLocalRect.X = UsingPlayer.Left;
                    OldLocalRect.Y = UsingPlayer.Top;
                    OldLocalRect.Width = UsingPlayer.Width;
                    OldLocalRect.Height = UsingPlayer.Height;
                    UsingPlayer.Dock = DockStyle.Fill;
                    UsingPlayer.BringToFront();
                }
                MenuStrip_Players.Refresh();
                this.Controls.Clear();
                Screen screen = Screen.FromControl(this.Parent);  //判断控件所在的屏幕
                fullscreenForm = new FullscreenFrom();
                fullscreenForm.StartPosition = FormStartPosition.Manual;  //此处必须设置为自定义,否则指定的位置无效
                fullscreenForm.Controls.Add(pnl_back);
                fullscreenForm.DesktopBounds = screen.Bounds;
                fullscreenForm.Left = screen.Bounds.Left;
                fullscreenForm.Top = screen.Bounds.Top;
                fullscreenForm.ShowDialog();
            }
            else
            {
                if (fullscreenForm != null)
                {
                    MenuItem_FullscreenSingle.Visible = true;
                    MenuItem_Fullscreen.Text = "多画面全屏";
                    MenuStrip_Players.Refresh();
                    if (m_FullSreenSingle == true)
                    {
                        m_FullSreenSingle = true;
                        UsingPlayer.Dock = DockStyle.None;
                        UsingPlayer.Left = OldLocalRect.X;
                        UsingPlayer.Top = OldLocalRect.Y;
                        UsingPlayer.Width = OldLocalRect.Width;
                        UsingPlayer.Height = OldLocalRect.Height;
                    }
                    fullscreenForm.Controls.Clear();
                    this.Controls.Add(pnl_back);
                    fullscreenForm.Close();
                    fullscreenForm = null;
                }
            }