Display a frame or form on a PC's second monitor...

Posted by MBeynon on 08-Aug-2017 03:03

Hello,

Using OE's .NET System.Windows.Forms.Screen:AllScreens I can get references to the two monitors on my PC and a handle to the parent frame or form's screen;

 myScreen = System.Windows.Forms.Screen:FromHandle(oAblParent).

Is it possible to programatically determine which PC monitor to display an ABL frame or form on?

Many Thanks,

Mark.

All Replies

Posted by vos on 08-Aug-2017 06:58

You should be able to use the static method Screen:FromControl(hForm) to return the Screen your form is currently displayed on.

Posted by MBeynon on 09-Aug-2017 02:35

Hi,

Thanks for the response.I finally cracked it with this code (which I've adapted from code I found on the progresstalk website and on the OE KB);

Get the screens on the PC and store them

DEFINE VARIABLE oScreenList AS "System.Windows.Forms.Screen[]" NO-UNDO.
DEFINE VARIABLE oScreen     AS System.Windows.Forms.Screen     NO-UNDO.

    oScreenList = System.Windows.Forms.Screen:AllScreens.
    
    DO vl_int = 0 TO oScreenList:LENGTH - 1 WITH FRAME default-frame:
      
      oScreen = CAST(oScreenList:GetValue(vl_int), System.Windows.Forms.Screen).
   
    
    END.

Pass to a procedure as myScreen for a form;

 DEFINE VARIABLE bounds AS CLASS System.Drawing.Rectangle NO-UNDO.

  bounds = myScreen:Bounds.
    
  myForm:SetBounds(bounds:X, bounds:Y, bounds:Width, bounds:Height).
 
  myForm:StartPosition = System.Windows.Forms.FormStartPosition:Manual.

and for a window;

  DEFINE VARIABLE bounds AS CLASS System.Drawing.Rectangle NO-UNDO.
 
  bounds = myScreen:Bounds.
 
  RUN VALUE("NewWindow.w") PERSISTENT SET lvhWindowHandle.
 
  ASSIGN
    lvhWindowHandle:CURRENT-WINDOW:X = bounds:X
    lvhWindowHandle:CURRENT-WINDOW:Y = bounds:Y
    lvhWindowHandle:CURRENT-WINDOW:Width-pixels = bounds:Width
    lvhWindowHandle:CURRENT-WINDOW:Width-pixels = bounds:Height.
    
  ASSIGN
    lvhWindowHandle:CURRENT-WINDOW:HIDDEN  = FALSE
    lvhWindowHandle:CURRENT-WINDOW:VISIBLE = TRUE. 

 

Hope this is of some use to somebody. It's not yet a polished solution but it's got me up and running :-)

Cheers,

Mark.

This thread is closed