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 :confused:
VBA 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
This document governs the use of our Community Forum. By registering and using the platform, you accept these conditions.
The COPA-DATA Community Forum serves to encourage the exchange of information and experience about the zenon software between forum users respectively zenon users.
Please mind that any published information on the Community Forum is the subjective opinion and view based on the experience and the level of knowledge of the author. COPA-DATA does not overtake any responsibility for the content and the accuracy of the shared information.
Users of the Community Forum are encouraged to share only well-founded experiences and to point out any risks associated with the implementation of proposed solutions to problems. COPA-DATA at its absolute discretion, reserves the right to moderate the forum. In this connection COPA-DATA may remove any information containing false facts, potentially dangerous solutions, bad language or content that may insult, degrade or discriminate others. COPA-DATA may block a non-complying user from forum access if the user violated this provision.
COPA-DATA reserves the right to change this document from time to time at own discretion.
Ing. Punzenberger COPA-DATA GmbH
Karolingerstraße 7b · 5020 Salzburg · Austria
www.copadata.com