【发布时间】:2016-12-20 10:09:32
【问题描述】:
我需要有关此解决方案的帮助。 有几种形式的申请。需要在选定的监视器上打开其中一个表单。例如: 解决方案 1. 如果使用了多个监视器,则 OnCreate 表单检查,并在最后一个上打开。我尝试了这段代码,但没有运气:
Application.CreateForm(TfrmDashboard, frmDashboard);
for I := 0 to Screen.MonitorCount -1 do
begin
// Checking Screen Position
ShowMessageFmt('%d, %d, %d, %d',
[Screen.Monitors[i].BoundsRect.Left,
Screen.Monitors[i].BoundsRect.Top,
Screen.Monitors[i].BoundsRect.Right,
Screen.Monitors[i].BoundsRect.Bottom]);
end;
if Screen.MonitorCount > 1 then
begin
frmDashboard.Top:= Screen.Monitors[i].BoundsRect.Top;
frmDashboard.Top:= Screen.Monitors[i].BoundsRect.Left;
end;
解决方案 2. 将窗体拖动到选定的监视器,并将 OnDestroy 事件的顶部和左侧位置写入 INI 文件。下次表格在同一显示器和同一位置打开。我尝试了这段代码,但也没有运气:
procedure TfrmDashboard.FormCreate(Sender: TObject);
var
ini: TIniFile;
begin
ini:= TIniFile.Create(extractfilepath(paramstr(0))+'Dashboard.ini');
Left:= StrToInt(ini.ReadString('Left', 'Form_Left', '0'));
Top:= StrToInt(ini.ReadString('Top', 'Form_Top', '0'));
ini.Free;
end;
procedure TfrmDashboard.FormDestroy(Sender: TObject);
var
ini: TIniFile;
begin
ini:= TIniFile.Create(extractfilepath(paramstr(0))+'Dashboard.ini');
ini.WriteString('Left', 'Form_Left', IntToStr(Left));
ini.WriteString('Top', 'Form_Top', IntToStr(Top));
ini.Free;
end;
【问题讨论】:
-
在与应用程序相同的目录中创建INI文件时需要小心。例如,如果应用程序位于 \program 文件中,某些版本的 Windows 会创建一个临时目录来存储 ini 文件,然后在程序退出时将其删除,这意味着它每次看起来都像是一个处女实现。例如,最好使用注册表或存储数据或使用文档目录。我可能有错误的技术细节,但这就是效果。
-
在“if”语句中的第一段代码中,您的意思是 Screen[1] 而不是 screen[i]。在你使用它时,我没有定义,可能包含任何垃圾。
标签: forms delphi multiple-monitors