Hello,
Here are two lines of code that I'm using to locate a child form, PrefDefPanel, to a specific location:
PreDefPanel.DesktopLocation = new Point(50, 25);
PreDefPanel.Show();
However, this does not work. Before the call to the Show(), debugged values of X and Y for PreDefPanel are 50 and 25, respectively. After the first call to Show(), those values were randomly set. For its subsequent calls, they both increment by 25 pixels! After awhile, they go back to their original values and then the form moves downward diagonally again!
What must I do to fix this problem?
Thanks,
LT
Loading
VulpesPosted Jul 29, 2011, 10:02 AM
Other settings include CenterScreen and CenterParent.
Lam ThaiPosted Jul 29, 2011, 10:30 AM
All the best,
LT
Zoran HorvatPosted Jul 29, 2011, 9:23 AM
Solution is to move the form after Windows determine its location, and here is the code sample which demonstrates that:
private void button_Click(object sender, EventArgs e)
{
Form frm = new Form();
frm.DesktopLocation = new System.Drawing.Point(100, 150); // This has no effect
frm.Shown += new EventHandler(frm_Shown);
frm.ShowDialog();
return;
}
void frm_Shown(object sender, EventArgs e)
{
Form frm = (Form)sender;
frm.DesktopLocation = new System.Drawing.Point(300, 400);
}
Setting coordinates to (100, 15) has no effect. Only when frm_Shown event handler is added, coordinates (300, 400) set within it will take effect.
Zoran