Results 1 to 2 of 2

Thread: Screen and Picturebox X, Y relationship - Need Help

  1. #1
    PowerPoster
    Join Date
    Jan 08
    Posts
    6,747

    Screen and Picturebox X, Y relationship - Need Help

    I have a Picturebox (ScaleMode = vbPixels) on a Form (ScaleMode = vbPixels) and at location 198, 207 in the Picturebox there is a dot. How do I figure this location to the screen's location? Also, how to figure screen coordinates to the picturebox coordinate of 198, 207?
    The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved


    When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day

  2. #2
    Frenzied Member
    Join Date
    Aug 11
    Location
    B.C., Canada
    Posts
    1,837

    Re: Screen and Picturebox X, Y relationship - Need Help

    this website since the update is slow and stop responding!!! what the **** is wrong? anyways back to your question


    i'm not exactly sure what you are asking but have a look at this

    Code:
    Private XX As Single
    Private YY As Single
    
    Private Sub Command1_Click()
    
    Picture1.DrawWidth = 2
    Picture1.Line (198, 207)-(198, 207), vbBlack
    
    Screen.MousePointer = vbHourglass
    For XX = 1 To Screen.Width
    For YY = 1 To Screen.Height
    DoEvents
    If Picture1.Point(XX, YY) = vbBlack Then
    MsgBox XX & " - " & YY
    Screen.MousePointer = vbDefault
    Exit Sub
    End If
    Next YY
    Next XX
    End Sub
    
    Private Sub Command2_Click()
    Dim ScreenX As Single
    Dim ScreenY As Single
    
    Picture1.BorderStyle = 0
    
    ScreenX = Form1.Left / Screen.TwipsPerPixelX + Picture1.Left + XX
    ScreenY = Form1.Top / Screen.TwipsPerPixelY + Picture1.Top + YY
    
    MsgBox "Dot is Placed at." & vbNewLine & "ScreenX (Pixels): " & ScreenX & vbNewLine & "ScreenY (Pixels): " & ScreenY
    
    Picture2.Move ScreenX - (Form1.Left / Screen.TwipsPerPixelX), ScreenY - (Form1.Top / Screen.TwipsPerPixelY), 1, 1
    End Sub
    click command1 to get coords from picturebox's black dot (takes a couple seconds)
    click command2 to get coords from screens then use it to move picture2 position on top on picture1's dot position (to see if coords are right)
    Attached Files Attached Files

Posting Permissions

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