Sam*_*Sam 3 c# forms windows-forms-designer winforms
我想在调用它的同一窗口中显示一个新表单.我知道一种在PrimaryScreen或虚拟屏幕上显示此表单的方法,代码如下所示:
MyForm.Location = Screen.PrimaryScreen.Bounds.Location;
Run Code Online (Sandbox Code Playgroud)
但我想在当前屏幕上显示它.有没有办法找出并在当前屏幕上显示它?
我做了类似这样的事情来显示我的表格以当前屏幕为中心:
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;
Run Code Online (Sandbox Code Playgroud)
您可以使用相同的技术,但不使用 PrimaryScreen,而是使用Screen.FromPoint和Cursor.Position抓取屏幕:
Screen screen = Screen.FromPoint(Cursor.Position);
MyForm.Location = screen.Bounds.Location;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6301 次 |
| 最近记录: |