鉴于Form我希望在切换屏幕后将表单置于中心位置.我怎样才能完成任务?
internal static void SetFormToBiggestMonitor(Form form, bool center = true)
{
Screen biggestScreen = FindBiggestMonitor();//assume this works
form.Location = biggestScreen.Bounds.Location;
if (center)
{
form.StartPosition = FormStartPosition.CenterScreen;
}
}
Run Code Online (Sandbox Code Playgroud)
一种不那么循环的方式来完成任务......
private static Point CenterForm(Form form, Screen screen)
{
return new Point(
screen.Bounds.Location.X + (screen.WorkingArea.Width - form.Width) / 2,
screen.Bounds.Location.Y + (screen.WorkingArea.Height - form.Height) / 2
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1594 次 |
| 最近记录: |