c# - 带有表单和面板的 MultiMonitor
问题描述
我有 3 台显示器连接。我想用表单覆盖整个 3 个屏幕,我想在主屏幕的中心显示面板。我该怎么做?
现在我已经用这段代码覆盖了每个屏幕。
int form_width = 0;
int form_height = 0;
int form_x = 0;
int form_y = 0;
int sub_screen_width = 0;
int sub_screen_height = 0;
bool minus_x = false;
bool minus_y = false;
foreach (Screen screen in Screen.AllScreens)
{
form_width += screen.Bounds.Width;
form_height += screen.Bounds.Height;
if (form_x > screen.Bounds.X)
{
minus_x = true;
form_x = screen.Bounds.X;
}
if (form_y > screen.Bounds.Y)
{
minus_y = true;
form_y = screen.Bounds.Y;
}
if (screen.Bounds.X < 0)
sub_screen_width += screen.Bounds.Width;
if (screen.Bounds.Y < 0)
sub_screen_height += screen.Bounds.Height;
}
this.Width = form_width;
this.Height = form_height;
this.CenterToScreen();
this.Location = new Point(form_x, form_y);
我应该为面板做什么?
解决方案
您可以使用 Screen.PrimaryScreen.WorkingArea。
panel1.Location = new Point(Screen.PrimaryScreen.WorkingArea.Left, Screen.PrimaryScreen.WorkingArea.Top);
panel1.Size = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
顺便说一句,要跨多个屏幕显示表单,您不需要遍历所有屏幕,而是可以使用 VirtualScreen。
this.Size = new System.Drawing.Size(SystemInformation.VirtualScreen.Width,
SystemInformation.VirtualScreen.Height);
this.Location = new Point(SystemInformation.VirtualScreen.Left,
SystemInformation.VirtualScreen.Top);
您可以在此处阅读有关 VirtualScreen的更多信息
推荐阅读
- json - Microsoft Graph FindMeetingTimes API - 仅返回 5 个位置?
- javascript - 是什么导致 Uint8Array 中字符串的索引偏移?
- python - 在树中查找元素的完整路径
- android - 使用 Google Pay for Xamarin 进行应用内预配
- scala - 错误 TransportResponseHandler:从节点连接时仍有 3 个请求未完成
- python - 验证表单时如何防止出现 no 'get' 属性错误?
- php - 如何用结果填充 HTML 表格并过滤它们
- java - 如何用 protobuf 表示未命名的对象列表?
- python - DynamodDB:如何更新排序键?
- r - 如何快速解析许多小的 JSON 文件?