I have a MDI(Parent) Form and 2 other Forms. On form1 there is a button, location is (X:100, Y:200). I required when user click on the button through Form1, another form "Form2" should open. And location of Form2 should be right middle of the button(Sender).
I write this code
Private Sub UpdateLocation(ByVal element As Control, ByVal frm As Form) Dim p As New Point(element.Location) p = element.PointToScreen(p) p.X = p.X + element.Width + 10 p.Y = p.Y / 2 Debug.Print(p.ToString) frm.Location = p frm.BringToFront() End Sub
but Form2 location is not as expected. In am calling the above function on button click event
UpdateLocation(form1.button1, form2)
Any help would be appreciable. Thanks in advance.
Output of the above code is:
After a few tests I realized that point.x (location.x) is working, but not the point.y (location.y)
You can download the piece of code from here. you can check the actual issues with it. VS2010 is required.