Results 1 to 5 of 5

Thread: Location Message box Help Urgent!!!!!

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    3

    Location Message box Help Urgent!!!!!

    I have just started learning VB and i have been given a small project to create a very basic game, everything has been going well so far but i have come across something which i have no idea how to do. I was wondering if there is any way in which i can make a message box pop up when a picture box reaches certain coordinates? Thank you!

  2. #2

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    3

    Re: Location Message box Help Urgent!!!!!

    Can anyone help?

  3. #3
    Frenzied Member IanRyder's Avatar
    Join Date
    Jan 2013
    Location
    Healing, UK
    Posts
    1,232

    Re: Location Message box Help Urgent!!!!!

    Hi,

    You can do this by creating an object of Type Rectangle which represents a region on your form. You can then use the IntersectsWith Method of the Bounds Property of the PictureBox to see if the PictureBox has reached the coordinates specified by the Rectangle. i.e:-

    Code:
    Public Class Form1
     
      Dim myRect As New Rectangle(100, 100, 50, 50)
     
      Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        PictureBox1.Left += 1
        PictureBox1.Top += 1
        If PictureBox1.Bounds.IntersectsWith(myRect) Then
          Timer1.Enabled = False
          MsgBox("Intersection Occured!")
        End If
      End Sub
     
      Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 100
        Timer1.Enabled = True
      End Sub
    End Class
    Hope that helps.

    Cheers,

    Ian

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    3

    Re: Location Message box Help Urgent!!!!!

    Thanks so much Ian! Just one last thing, how do i set the location of the rectangle? Like i said, new to VB
    Thanks so much

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Location Message box Help Urgent!!!!!

    The location of which rectangle? Ian created one rectangle directly with this line:

    Dim myRect As New Rectangle(100, 100, 50, 50)

    The rectangle for the control came from this piece (which is part of a larger line):

    PictureBox1.Bounds
    My usual boring signature: Nothing

Posting Permissions

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



Click Here to Expand Forum to Full Width