My goal is to let the user click on a specific location on a map to add a Placemark, and then edit the placemark by click its icon (change its name, move it around, etc). I am using a PictureBox to show the map, and by registering the MouseDoubleClick event I am drawing an Image on the map with GDI+ DrawImage() method. The problem is that after the placemark's Image was drawn, it does not editable: the user cant click the icon and move it around, change its name etc. Is there any other design pattern I can follow? maybe using other controls... ?
You need to have a concept of layering the items. When you place that icon on the image, you need to store its coordinates/size in an array. If the user clicks the icon, you can detect its location based on the stored coordinates and then allow the user to select/move it around, redrawing the image as they do this, based on your main background image + the layered array of icons.
You can have a list of objects that each of them is a placemark in your screen. these objects have at least 2 properties X and Y and a method public bool Contain(int x, int y)
that say you this object contains this point or no.
public class placemark
{
public int X;
public int Y;
public bool Contain(int x, int y)
{
// some logic here
return true;
}
}
When user clicks on the screen, by a foreach loop check that each object contains the mouse position to find the object that user wants to select it.
foreach(var placemark in placeMarkList)
{
if (placemark.Contain(e.x,e.y))
{
placemark.X+=e.x-oldx;
placemark.X+=e.y-oldy;
}
}
So you can change the properties X and Y of that object and Invalidate() Picturebox.