如何在C#的当前屏幕上显示表单? [英] How to show a form on current screen in C#?

查看:73
本文介绍了如何在C#的当前屏幕上显示表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在调用它的同一窗口中显示一个新表单. 我知道一种通过类似于以下代码的方式在PrimaryScreen或Virtual Screen上显示此表单的方法:

I want to show a new form in the same window from where it was invoked. I know a way to show this form on PrimaryScreen or Virtual Screen by code similar to as below:

MyForm.Location = Screen.PrimaryScreen.Bounds.Location;

但是我想在当前屏幕上显示它. 有没有办法找出并显示在当前屏幕上?

But i want to show it on current screen. Is there a way to find out and show it on current screen?

推荐答案

我已经做了类似的事情来将我的表单显示在当前屏幕的中央:

I have done something like this to show my form centered to the current screen:

var screen = Screen.FromPoint(Cursor.Position);
myForm.StartPosition = FormStartPosition.Manual;
myForm.Left = screen.Bounds.Left + screen.Bounds.Width / 2 - myForm.Width / 2;
myForm.Top = screen.Bounds.Top + screen.Bounds.Height / 2 - myForm.Height / 2;

这篇关于如何在C#的当前屏幕上显示表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆