We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

# Draw a filled square or circle ....  at my x,y

on
Medium Priority
595 Views
I have been marking places on my map with small picture boxes in fact they are 5x5 and are red ... it looks like a small red square .... sort of like the square you see on wikimapia when you select the measuring tool from geotools ... it gives you this line with a sqaure to mark each selected point.

I am wanting to make a square or a circle that size to mark my map and do away with the pictur box controls ...

I am going to give an example of how I am marking my map and ask if you could show me how to mark the map with a filled square or circle ....

Here is the code
``````If mMarkers = True Then
Dim myX As Integer
Dim myY As Integer
myX = (tlLon - myLon) / delX
myY = (tlLat - myLattitude) / delY
Me.Text = myX & "," & myY

Dim PB As New PictureBox ' Create a PictureBox
Dim mT As New ToolTip

mT.SetToolTip(PB, "The X,Y Coordinates are: " & myX & ", " & myY)
mT.IsBalloon = True
mT.ToolTipTitle = "Lat: " & myLattitude & " Lon: " & myLon
mT.BackColor = Color.Azure

With PB
.Location = New System.Drawing.Point(myX, myY) ' on Mouse click place PB
.Size = New Size(5, 5)
.BackColor = Color.Red
.BringToFront()

End With

Else
' Dont place a marker
End If
``````
Comment
Watch Question

## View Solution Only

High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
What are you "marking" ON?...is it a PictureBox that has the Map in it?

Anyhoo, just store the x,y values in an ArrayList or List and then in the Paint() event iterate thru them and draw the markers...

Commented:
I have a image inside a picturebox ..... I presently mark a spot by clicking the place I want and a smaller picuture box is created as seen in the code above and placed at that x,y coordinate.
I used pictureboxes to mark the spot cause I do not kjnow how to use the draw features of vb this is my work around

I would like to use a filled square or circle .... to mark the area I click on .... instead of using picturebox controls

How do I do it?

Ok about the arrays ... not needed ... as I am marking the spot on mouse click so the mark should be placed where the user clicks within in the picture box .....

Mark

Commented:
My bad .... left something out

The code I gave is within the Picturebox1_Mouseclick event

1. User clicks on spot on map
2. Code above is activated creates a smaller picture box and places it a the x,y coordinates where user clicked.

Iagain simply would not want to use pictureboxes ... ideally I would like to use a drawn filled square to mark the spot .... then when the users is ready can alos simply clear picture box of all marks they placed on the map.

Since this happens in the Picturebox mouseclick event I do not see the need for arrays to iterate through as the mark is placed at the e.X & e.Y or in my code the myX and myY x,y coordiinates.

I hope this is clear if not ask away

High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009
Commented:
This is really simpler to implement than you think!...

The following code allows you to place as many circular dots on the PictureBox as you want...and also shows how to erase all of them:
``````Public Class Form1

Private marks As New List(Of Point)

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
PictureBox1.Refresh()
End Sub

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
For Each pt As Point In marks
Dim rc As Rectangle = New Rectangle(pt.X, pt.Y, 1, 1)
rc.Inflate(6, 6)
e.Graphics.FillEllipse(Brushes.Red, rc)
Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' clear all the marks
marks.Clear()
PictureBox1.Refresh()
End Sub

End Class
``````

Not the solution you were looking for? Getting a personalized solution is easy.

Commented:
This is simple ... I had no idea ..... and it works perfectly ... may I ask .... can I assign a tooltip to it as I did to the pb's I used ..... I didn't see any properties for it .....

Note this the solution .... I'll understand if you would not want answer a 2nd question but couldnt help but ask

Great code

Commented:
Easy to understand and was exactly what I needed .. works perfect
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
Therein lies the tradeoff...since we are not making actual controls we have to manage any custom action by manually hit-testing the cursor position against all known "marks".

I'll post another example later today...
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
Try this example out...the form has an additional Label and a ContextMenuStrip with a menu called "Delete":
``````Public Class Form1

Private Dist As Integer = 6
Private Counter As Integer
Private Marks As New List(Of Mark)
Private CurMark As Mark = Nothing

Private Class Mark

Public Pt As Point
Public Data As String

Public Sub New(ByVal pt As Point, ByVal data As String)
Me.Pt = pt
Me.Data = data
End Sub

End Class

Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Right Then
ElseIf e.Button = Windows.Forms.MouseButtons.Left Then
Counter = Counter + 1
Marks.Add(New Mark(PictureBox1.PointToClient(Cursor.Position), "Mark #" & Counter))
PictureBox1.Refresh()
End If
End Sub

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
For Each m As Mark In Marks
Dim rc As Rectangle = New Rectangle(m.Pt.X, m.Pt.Y, 1, 1)
rc.Inflate(Dist, Dist)
If rc.Contains(New Point(e.X, e.Y)) Then
CurMark = m
Label1.Text = m.Data
Exit Sub
End If
Next
CurMark = Nothing
Label1.Text = ""
End Sub

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
For Each m As Mark In Marks
Dim rc As Rectangle = New Rectangle(m.Pt.X, m.Pt.Y, 1, 1)
rc.Inflate(Dist, Dist)
e.Graphics.FillEllipse(Brushes.Red, rc)
Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' clear all the marks
Marks.Clear()
CurMark = Nothing
Label1.Text = ""
PictureBox1.Refresh()
End Sub

Private Sub DeleteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteToolStripMenuItem.Click
If Not IsNothing(CurMark) Then
Marks.Remove(CurMark)
CurMark = Nothing
Label1.Text = ""
PictureBox1.Refresh()
End If
End Sub

End Class
``````
PictureBoxMarks.jpg

Commented:
This was interesting ... and a real eye opener

I am playing this cod right now ... thanx very much .... let me really think about othe methods I would not have even begin to consider

Mark
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile