Based on my understanding, the main part of your problem is how to find the positions of a control in picture box. BinaryCoder has already shown the key problem. The code snippet below explains the idea:
Panel panel;
PictureBox picBox;
Button bt;
private void Form1_Load(object sender, EventArgs e)
{
panel = new Panel();
panel.Location = new Point(20, 20);
panel.Size = new Size(200, 200);
panel.BorderStyle = BorderStyle.FixedSingle;
this.Controls.Add(panel);
picBox = new PictureBox();
picBox.Location = new Point(5, 5);
picBox.Size = new Size(100, 100);
picBox.BorderStyle = BorderStyle.Fixed3D;
this.panel.Controls.Add(picBox);
bt = new Button();
bt.Name = "bt";
bt.Location = new Point(2, 2);
bt.Text = bt.Name;
bt.Size = new Size(30, 30);
this.picBox.Controls.Add(bt);
bt.Click += new EventHandler(bt_Click);
}
private void bt_Click(object sender, EventArgs e)
{
Point posInScreen = bt.PointToScreen(Point.Empty);
string posInfo = "";
posInfo += "In PictureBox:" +
GetLocation(this.picBox.PointToClient(posInScreen))
+ "\r\n";
posInfo += "In Panel:" +
GetLocation(this.panel.PointToClient(posInScreen))
+ "\r\n";
posInfo += "In form:" +
GetLocation(this.PointToClient(posInScreen))
+ "\r\n";
MessageBox.Show(posInfo);
}
private string GetLocation(Point p)
{
return p.X + ":" + p.Y;
}
Let me know if this helps.
Best regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't.