c# winfrom 子窗体分屏显示


参考博客:https://blog.csdn.net/kailan818/article/details/8517126

实现代码:

private void button1_Click(object sender, EventArgs e)
        {
            var frmChild = Application.OpenForms["frmChild"];
            if (frmChild != null)
            {
                frmChild.Activate();
            }
            else
            {
                frmChild frm = new frmChild();
                frm.Owner = this;//申明当前窗体是子窗体
                ShowOnMonitor(frm);
                frm.Show();
            }
        }

        private void ShowOnMonitor(frmChild frm)
        {
            Screen[] sc = Screen.AllScreens;
            if (sc.Length > 1)
            {
                //获取当前屏幕
                Screen CurrentScreen = Screen.FromControl(this);
                //获取当前鼠标所在的屏幕
                //Screen CurrentScreen = Screen.FromPoint(new Point(Cursor.Position.X, Cursor.Position.Y));
                var child = sc.Where(it => it.DeviceName != CurrentScreen.DeviceName).FirstOrDefault();
                frm.StartPosition = FormStartPosition.Manual;
                frm.Location = new Point(child.Bounds.Left, child.Bounds.Top);

            }
            // If you intend the form to be maximized, change it to normal then maximized.  
            frm.WindowState = FormWindowState.Normal;
            frm.WindowState = FormWindowState.Maximized;
        }

demo地址:https://gitee.com/cainiaoA/winformSplit


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM