Picbox location

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von Adam.

    Picbox location

    Haii@all
    also
    wie kann ich prüfen ob eine picturebox den bildschirmrand berührt.
    also ich habe
    Topmost = true
    Transparensykey = white
    backcolor = white
    picturebox1.image = gehender Mensch
    so und wenn die picbox den linken rand berührt soll sie das bild ändern

    Das ist der Code:

    VB.NET-Quellcode

    1. Public Class Form1
    2. Dim rectScr As New Rectangle
    3. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    4. PictureBox1.Location = New Point(PictureBox1.Location.X + 50, PictureBox1.Location.Y)
    5. End Sub
    6. Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
    7. rectScr = Screen.PrimaryScreen.Bounds
    8. If PictureBox1.Left <= rectScr.Left Then
    9. Timer2.Stop()
    10. Timer1.Start()
    11. PictureBox1.Image = My.Resources.gehen_rechts
    12. End If
    13. If PictureBox1.Right <= rectScr.Right Then
    14. Timer1.Stop()
    15. Timer2.Start()
    16. PictureBox1.Image = My.Resources.gehen_links
    17. End If
    18. End Sub
    19. Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    20. PictureBox1.Location = New Point(PictureBox1.Location.X - 50, PictureBox1.Location.Y)
    21. End Sub
    22. End Class

    Nur leider funktioniert der nicht.
    ps: timer 3 läuft immer

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „markushettmann“ ()

    VB.NET-Quellcode

    1. Private Sub Form1_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LocationChanged
    2. If Me.Location.X + PictureBox1.Location.X + 6 < 0 Then
    3. 'Jetzt ist er am linken bildschirmrand
    4. End If
    5. End Sub

    Probiers mal so

    //edit:

    VB.NET-Quellcode

    1. If Me.Location.X + PictureBox1.Location.X + PictureBox1.Width + 10 > My.Computer.Screen.Bounds.Width Then
    2. 'Jetzt ist er am rechten rand
    3. End If

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „okster“ ()