当前位置: 首页 > news >正文

【Delphi】实现在多显示器时指定程序运行在某个显示器上

在多显示器时代,经常会出现期望将程序运行在某个指定的显示器上,特别是在调试程序的时候,期望切换分辨率,单步调试时,此时容易导致互相卡住,非常不方便,但是通过指定程序运行在不同的显示器上就可以解决这个问题。

代码如下:

usesVcl.Forms, Winapi.Windows;procedure MoveFormToScreen(AForm: TForm; ScreenIndex: Integer);
beginif (ScreenIndex >= 0) and (ScreenIndex < Screen.MonitorCount) thenbeginAForm.Left := Screen.Monitors[ScreenIndex].BoundsRect.Left;AForm.Top := Screen.Monitors[ScreenIndex].BoundsRect.Top;AForm.Width := Screen.Monitors[ScreenIndex].BoundsRect.Width;AForm.Height := Screen.Monitors[ScreenIndex].BoundsRect.Height;// 可选:如果只想让窗口在特定屏幕上显示// 例如居中AForm.Position := poDesigned; AForm.Left := Screen.Monitors[ScreenIndex].BoundsRect.Left +(Screen.Monitors[ScreenIndex].BoundsRect.Width - AForm.Width) div 2;AForm.Top := Screen.Monitors[ScreenIndex].BoundsRect.Top +(Screen.Monitors[ScreenIndex].BoundsRect.Height - AForm.Height) div 2;endelseraise Exception.Create('Invalid ScreenIndex');
end;

使用示例

在窗体的 OnCreate 事件中调用:

procedure TForm1.FormCreate(Sender: TObject);
begin// 放置在第二个屏幕(索引1)MoveFormToScreen(Self, 1);
end;

相关文章:

  • 使用 OpenCV (C/C++) 通过二值化增强车牌识别
  • 如何选择合适的哈希算法以确保数据安全?
  • AJAX对于XML和JSON的处理
  • 腾讯云 Python3.12.8 通过yum安装 并设置为默认版本
  • dify应用探索
  • 基于ubuntu和树莓派环境对游戏进行移植
  • imx6ull(0):烧录、启动
  • JavaSE:面向对象进阶之内部类(Inner Class)
  • Uiverse.io:免费UI组件库
  • 通信革新与网络安全探索与创新:开启未来之门
  • MySQL-多表关系、多表查询
  • 绿盟 IPS 设备分析操作手册
  • 详细解析2MHz和3MHz压电陶瓷片的区别
  • TomSolver 库 | config详解及其测试
  • 嵌入式Linux 期末复习指南(下)
  • Java如何读取CSV文件并将数据放入对象中详解
  • GMDCMonitor企业版功能分享0602
  • Python列表、字典、元组、集合
  • 系统级 EOS 测试方法 - System Level EOS Testing Method
  • 【设计模式-3.5】结构型——装饰器模式
  • wordpress实名认证/网络seo优化平台
  • wordpress大前端哪个好/推广seo优化公司
  • mt4网站可做黄金交易/谷歌排名推广
  • 网站备案失败/seo基础入门视频教程
  • 免费java我的世界/优化资源配置
  • 潍坊网站建设(首选聚搜网络)/app推广拉新