Showing results 1 to 4 of 4

Thread: Multiscreen with VBA - show VBA form on the dedicated monitor

  1. #1
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    879

    Default Multiscreen with VBA - show VBA form on the dedicated monitor

    I have a multimonitor system (3 monitors) and have created some VBA forms. When I want to call i.e. the VBA form at the thrid monitor the form always appears on the first monitor
    At the multimonitor configuration the monitor are sperated i.e. as follow:
    1. monitor: 0 - 1024
    2. monitor: 1024 - 2048
    3. monitor: 2048 - 3072

    To know from which monitor the form has been requested you can get the actual cursor position with using a WinAPI function. Simply speaking when pressing on the button to show the form you know at which monitor you are working and with giving the form an offset in x-direction you can handle this issue.

    At the form you want to show you need this setting:
    StartUpPosition -> 0 - manual


    Below a sample code:

    -------------------------------------------------------------
    
    Public Sub LeftClickUp_Default(obElem As Element)    'this is the VBA Makro which is linked to the LeftClickUp Event of the element (i.e. text button)
    Dim NewForm As New MyForm1           'MyForm1 is the name of the UserForm
    
        NewForm.Init obElem         'hand over all properties to the procedure "Init"
        obElem.LeftClickUp           'release the button
    End Sub
    -------------------------------------------------------------
    
     
    
    'in the VBA Form you have to insert following code (you also can handle this in a sperate module)
    
    'declare the WinAPI in order to get curser position
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Type POINTAPI
    x As Long
    y As Long
    End Type
    
    Sub GetMyCurserPosition()
    Dim pTargetPoint As POINTAPI
    Dim lRetVal As Long
    
        lRetVal = GetCursorPos(pTargetPoint)
    
        'check if the cursor position is at the 1. screen
        If pTargetPoint.x < 1024 Then
            MyForm1.Left = 400  'place the form on the 1. screen (depends on the width of the form)
    
        'check if the cursor position is at the 2. screen
        ElseIf pTargetPoint.x >= 1024 And pTargetPoint.x < 2048 Then
            MyForm1.Left = 1400  'place the form on the 2. screen (depends on the width of the form)
    
        'otherwise its on the 3. screen
        Else
            MyForm1.Left = 2400  'place the form on the 3. screen (depends on the width of the form)
        End If
    
        MyForm1.Top = 200   'set the offset from the top of the form (depends on the height of the form)
        MyForm1.Show (0)
    End Sub
    
    Sub Init(obElem As Element)
    
        Call UserForm_Load
    End Sub
    
    'every time the form is loaded the new position is calculated
    Private Sub UserForm_Load()
    
        Call GetMyCurserPosition
    End Sub
    Last edited by admin : 22nd August 2007 at 09:16 Reason: testint

  2. #2
    Join Date
    11.04.2008
    Posts
    40

    Default Re: Multiscreen with VBA - show VBA form on the dedicated monitor

    Thanks, looks like this will do the job

  3. #3

    Default Re: Multiscreen with VBA - show VBA form on the dedicated monitor

    With zenon version 7, or 6.51 and the latest build, you will be able to read out the monitor for the object that was clicked on, via the parent (screen) object.

    (reference QC#23793 in case you contact your local COPA-DATA support)

  4. #4
    martins Gast

    Default Re: Multiscreen with VBA - show VBA form on the dedicated monitor

    hello,

    I attached a small sample project for 6.51 written in VB.NET that I used for testing. I know it's not the prettiest one but it does the job
    I don't know if you prefer VBA or VSTA, but I think you can take a look at it and get a general idea of how it works.

    hope I could help
    Attached Files Attached Files

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •