Reputation: 1593
I have a panel control with a label and textbox next to each other. In certain translations the label becomes too long and I'm trying to use GetChildAtPoint
to determine when the label has become too long and shorten it appropriately (I know there's other/better ways, but I'm somewhat limited in my approach, hence this option).
I've checked the index and the label is 41, while the textbox is 0.
I use panelControl.GetChildAtPoint(new Point(labelControl.Location.X + labelControl.Width, labelControl.Location.Y))
to try and determine if the label is too long or not, but for some reason, the above code returns the label control instead of the text box.
In debug, labelControl.Location
= 566, 305 and textBoxControl.Location
= 716, 290. The label control has a width of 202.
I've seen this approach work in other instances and cannot see any differences here, so I'm really unsure as to why it's not working in this scenario.
Upvotes: 0
Views: 69
Reputation: 673
It seems no problem with your code, please add some testing to see actually size and location change in run time
Eg:
var point = new Point(label1.Location.X + label1.Width,
label1.Location.Y);
var p2 = panel1.Controls[1].Location;
var ctrl = panel1.GetChildAtPoint(point);
if (ctrl is TextBox)
{
textBox1.Text = "Got TextBox";
}
else if (ctrl is Label)
{
textBox1.Text = "Got Label";
}
textBox1.Text += string.Format(" {0}:{1} {2}:{3}", point.X, point.Y, p2.X, p2.Y);
Upvotes: 1