3

I am working on a mapped DVR/cctv UI.
I made it myself, so I did not use google's API. I just cut off big part of the map where I need it.

so, if I do have a really big map, then it won't fit in my pc's resolution, I haven't found a code to move the picture inside the pictureBox, but what I did is to move the pictureBox inside a panel. then it looked like a map, with boundaries. :)

now, I want to be able to save/attach this button to the picture.. so whenever and wherever I move the pictureBox, button gets along with it. even if goes outside the form, but when I drag it back, it appears to where it was let's say, attached just imagine the button like googlemap's marker. that's what I wanted to happen.

its like I am building my own offline google map..

enter image description here

if you have queries, feel free to ask. TIA

AdorableVB
  • 1,383
  • 1
  • 13
  • 44
  • You will have to calculate the position of the button according to the map position and set them on map event – Nadeem_MK Nov 27 '13 at 06:21
  • its not actually a map, its only a **picture** of the map. also, I don't know how to do that, I learn via understanding the code. :) – AdorableVB Nov 27 '13 at 06:25
  • The button has 2 properties, `Location.X and Location.Y` which you can manipulate to move the button programmatically on execution. – Nadeem_MK Nov 27 '13 at 06:32
  • do I really need to calculate its location if it needs to be referenced to the picture? – AdorableVB Nov 27 '13 at 06:36

1 Answers1

2

Simply add your button as a child of your picturebox:

button1.Parent = pictureBox1;
//or
pictureBox1.Controls.Add(button1);

Then you can use the Location property of your button to set it accordingly, that location is relative to your pictureBox, not your form.

If you want to keep the design location of your button, you can try this code:

Point loc = pictureBox1.PointToClient(button1.PointToScreen(Point.Empty));
button1.Parent = pictureBox1;
button1.Location = loc;
King King
  • 61,710
  • 16
  • 105
  • 130
  • let me try, I think, if you first put/add your button on top of the picture box, its location is relative to it. I have been thinking of how much was added to the location of my picture then I need to add the same thing to the button, but I think that it will have discrepancies, before that I will try this. – AdorableVB Nov 27 '13 at 06:44
  • @AdorableVB no problem, just try it, if there is any other trouble around that approach, just ask it here as a comment, I'll try to help. – King King Nov 27 '13 at 06:50
  • it seems to adopt the picturebox' location, but one thing, it saves the initial position of the form, on design view not the picture. its not the one that I expected, but it does what it needs to do (draggable with the picture) and I think that I will have future problems if I use this. any other solutions? – AdorableVB Nov 27 '13 at 06:55
  • can you help me with this http://stackoverflow.com/questions/20236430/move-winform-in-relation-to-a-button-from-another-form-vb-c – AdorableVB Nov 27 '13 at 07:36