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!
Re: Location Message box Help Urgent!!!!!
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
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
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