claire_bicknell
Well-known member
- Joined
- Dec 10, 2008
- Messages
- 49
- Programming Experience
- Beginner
I have an interactive map as illustrated in screenshot 1. The user is expected to select a point on the map and then depending on the region clicked (i.e Manchester), on a second form (see screenshot 2) the centreName and Postcode should be automatically entered into textboxes on the second form ready for the user to click "search for directions".
This is my full code for form1 (interactive map):
This is the fragment of code I am working on to try and get this working:
Currently when i select a region on the map... it returns the same result (centreName and Postcode for Belfast) no matter what region is clicked. Obviously the centreName and Postcode should differ depending on the region clicked.
I hope someone can help.
Kind Regards
This is my full code for form1 (interactive map):
HTML:
Imports System
Imports System.Data.Sql
Imports System.Data.SqlClient
Public Class Form1
Private places As New Dictionary(Of String, Rectangle)
Const strConnection As String = "Data Source=(local);Initial Catalog=ShoppingCentre;Integrated Security=True"
Dim con As New SqlConnection(strConnection)
Dim com As New SqlCommand("Select * from dbo.Centre", con)
Dim MyDataSet As New DataSet()
Dim CentreTableAdapter As New SqlDataAdapter()
Private Sub LoadPlaces()
Me.CentreTableAdapter.Fill(MyDataSet, "Centre")
For Each row As DataRow In MyDataSet.Tables("Centre").Rows
places.Add(row.Item("CentreName") & vbCrLf & ("Address: ") & row.Item("Address") & (", ") & row.Item("Postcode") & vbCrLf & ("Phone: ") & row.Item("TelephoneNumber") & vbCrLf & ("Opening Times: ") & row.Item("OpeningClosingTimes"), New Rectangle(row.Item("X1"), row.Item("Y1"), row.Item("X2"), row.Item("Y2")))
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CentreTableAdapter.SelectCommand = com
LoadPlaces()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
For Each hotspot As Rectangle In places.Values
e.Graphics.DrawEllipse(Pens.Red, hotspot)
Next
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
For Each place As String In places.Keys
If places(place).Contains(e.Location) Then
For Each row As DataRow In MyDataSet.Tables("Centre").Rows
Directions.TextBox1.Text = row.Item("CentreName")
Directions.TextBox2.Text = row.Item("Postcode")
Stores.Show()
Me.Hide()
Next
Exit For
End If
Next
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
Dim current As String = Me.ToolTip1.GetToolTip(Me.PictureBox1)
For Each place As String In places.Keys
If places(place).Contains(e.Location) Then
If current <> place Then
Me.ToolTip1.Show(place, Me.PictureBox1)
Exit For
End If
End If
Next
End Sub
Private Sub StoresToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StoresToolStripMenuItem.Click
Stores.Show()
Me.Hide()
End Sub
Private Sub FloorPlanToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FloorplanToolStripMenuItem.Click
Floor_Plan.Show()
Me.Hide()
End Sub
Private Sub DirectionsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DirectionsToolStripMenuItem.Click
Directions.Show()
Me.Hide()
End Sub
Private Sub ContactUsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContactUsToolStripMenuItem.Click
Contact_Us.Show()
Me.Hide()
End Sub
Private Sub LeaveYourCommentsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LeaveYourCommentsToolStripMenuItem.Click
Leave_your_Comments.Show()
Me.Hide()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub AdminToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AdminToolStripMenuItem.Click
Admin.Show()
Me.Hide()
End Sub
End Class
This is the fragment of code I am working on to try and get this working:
HTML:
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
For Each place As String In places.Keys
If places(place).Contains(e.Location) Then
For Each row As DataRow In MyDataSet.Tables("Centre").Rows
Directions.TextBox1.Text = row.Item("CentreName")
Directions.TextBox2.Text = row.Item("Postcode")
Stores.Show()
Me.Hide()
Next
Exit For
End If
Next
End Sub
Currently when i select a region on the map... it returns the same result (centreName and Postcode for Belfast) no matter what region is clicked. Obviously the centreName and Postcode should differ depending on the region clicked.
I hope someone can help.
Kind Regards