-5

I want to create a api which can keep track of my delphi application's forms in dual monitor if form open on second monitor then next form should be there. this track will be done my api in c# windows app. please guid

Description:

I have an delphi application. when u used dual monitor then following issue occurred. let see scenario:

there are three from 1, 2 ,3 from 2 will open after clicking on button on from 1 and from 3 will open after clicking on button on from 2. all works fine when monitor is single. Now when i connect second monitor then form 1 will open by default on primary monitor which is first monitor, when i moved form 1 from monitor 1 to monitor 2 and click on button of form 2 to open form 3 then it is opening on monitor 1 instead of monitor 2. it should be open on monitor 2 means on monitor where last open form located. I am not able to implement it in my delphi code. So i thought to make one api in c# which will do this work of tracking window for my delphi application.

  • 1
    Why in the world would you think you need to use C# for this instead of just handling it in your own Delphi code? – Ken White Apr 03 '17 at 12:39

1 Answers1

0

You do not need C# to do this, it can be done with Delphi. The following code can be added to each forms OnCreate or OnShow event:

var
 m: TMonitor;
 cp: TPoint;
begin
  // Get the Cursor Position
  GetCursorPos(cp);
  // Get the Monitor the Cursor is on
  m := Screen.MonitorFromPoint(cp);
  // Position the Form on the correct Monitor, about the center
  Self.Top  := ((Screen.Monitors[m.MonitorNum].Height - 30) div 2) - (Self.Height div 2);
  Self.Left := (Screen.Monitors[m.MonitorNum].Width div 2) - (Self.Width div 2) + m.Left;
TDC
  • 377
  • 1
  • 6