Move winform relative to button from another vb / c # form

I want to check this one first .

that I work, the problem is solved on the button, and now I need to make WinForm, following the button, wherever and whenever I drag the map / image. it is something like this, infowindows in google API. first shot, I took it in html.

enter image description here

and this ... this is what I'm working on now, on winForms, I can not drag form2 with the image .. enter image description here

this is my current code.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim loc As Point = PictureBox1.PointToClient(Button1.PointToScreen(Point.Empty))
    Button1.Parent = PictureBox1
    Button1.Location = loc

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Form2.Show()
End Sub

Private Sub pictureBox1_LocationChanged(ByVal sender As Object, ByVal e As EventArgs)

    Dim p As Point = button1.PointToScreen(Point.Empty)
    p.Offset(5, 10)
    Form2.Location = p
    Form2.Owner = Me
End Sub

as you can see, this is infowindow, I want it to be a form in my winForms. Is it possible that its location can be relative / parent to the button in the same way as from the link above. thanks!

+1
1

LocationChanged :

//LocationChanged event handler for your pictureBox1
private void pictureBox1_LocationChanged(object sender, EventArgs e){
  //Get the location of button1 in screen coordinates
  Point p = button1.PointToScreen(Point.Empty);
  //Offset it to what you want
  p.Offset(5,10);
  //set the location for your infoWindow form
  infoWindow.Location = p;
}

, infoWindow , , , FormBorderStyle None ... ( , ). , LocationChanged, :

pictureBox1.LocationChanged += pictureBox1_LocationChanged;

, infoWindow :

infoWindow.Owner = yourMainForm;
//or this if the code is placed inside mainForm class
infoWindow.Owner = this;

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Dim loc As Point = PictureBox1.PointToClient(Button1.PointToScreen(Point.Empty))
  Button1.Parent = PictureBox1
  Button1.Location = loc
  Form2.Owner = Me
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  Form2.Show()
End Sub

Private Sub pictureBox1_LocationChanged(ByVal sender As Object, ByVal e As EventArgs) Handles PictureBox1.LocationChanged

  Dim p As Point = button1.PointToScreen(Point.Empty)
  p.Offset(-Form2.Width/2, -Form2.Height-10)
  Form2.Location = p

End Sub
+4

All Articles