Hi Abhishek,
Thank you for your sample project. I run it on my machine and did see the problem on my side.
When a child control inside a container, e.g. a Panel receives the focus, it will ask its container to scroll (if possible) so as to display the child control completely. This behavior is by design.
If you don’t want the container to scroll when the child control gets focused, a workaround is to catch the WM_LBUTTONDOWN Windows message sent to the child control and discard it. To do this, override the WndProc method in the child control and set the container focused when the WM_LBUTTONDOWN message is caught.
public partial class Grid : UserControl
{
int WM_LBUTTONDOWN = 0x201;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_LBUTTONDOWN)
{
if (this.Parent != null)
{
this.Parent.Focus();
}
}
else
{
base.WndProc(ref m);
}
}
}
It works well on my side. Please try it on your machine to see if it solves your problem.
Sincerely,
Linda Liu