I've got this code in an module:
VB Code:
Public Function GetScreenPixels(Optional Dimension As Integer, Optional MinusForm As Form) If Not MinusForm Is Nothing Then 'Get maximum position for form If Dimension = 1 Then 'Y GetScreenPixels = (Screen.Height - MinusForm.Height) / Screen.TwipsPerPixelY Else 'X GetScreenPixels = (Screen.Width - MinusForm.Width) / Screen.TwipsPerPixelX End If Else 'Get screen size in pixels If Dimension = 1 Then 'Y GetScreenPixels = Screen.Height / Screen.TwipsPerPixelY Else 'X GetScreenPixels = Screen.Width / Screen.TwipsPerPixelX End If End If End Function
The function is for returning the users screen width and height in pixels. however, when i use this code to call it;
It doesn't work. My resolotion is 1280x1024. When changing the txtPosX text to a number which is more than 1, i get "Outside screen!". changing txtPosY doesn't work either, only numbers below 1 are accepted.VB Code:
Private Sub txtPosX_LostFocus() On Error GoTo Error 'Allow form to edit values If auto_change = True Then Exit Sub If txtPosX.Text > GetScreenPixels(0) Then MsgBox ("Outside screen!") txtPosX.Text = GetScreenPixels(0, frmMain) End If Exit Sub Error: MsgBox ("Only numbers are allowed as window positions!") txtPosX.Text = 0 End Sub Private Sub txtPosY_LostFocus() On Error GoTo Error 'Allow form to edit values If auto_change = True Then Exit Sub If txtPosY.Text > GetScreenPixels(1) Then MsgBox ("Outside screen!") txtPosY.Text = GetScreenPixels(1, frmMain) End If Exit Sub Error: MsgBox ("Only numbers are allowed as window positions!") txtPosY.Text = 0 End Sub
Does anyone have a solution to this?





Reply With Quote

