I create a bunch of forms, and I want to save and restore their position on application close/startup.
However, if the form is not visible, then the .top
and .left
are both 0. Only when it's visible are these properties populated with their 'real' values.
Right now my kludge is to show each form, save the info, then return it to its previous visible state:
int i;
bool formVisible;
// Show all current forms and form positions in array frmTestPanels
i = 0;
while (frmTestPanels[i] != null)
{
formVisible = frmTestPanels[i].Visible;
frmTestPanels[i].Visible = true;
note(frmTestPanels[i].Text + "(" + frmTestPanels[i].Left.ToString() + ", " + frmTestPanels[i].Top.ToString() + ") visible: " + formVisible.ToString());
frmTestPanels[i].Visible = formVisible;
i++;
}
note(i.ToString() + " forms present");
note()
is a simple function that just displays information.
This, of course, results in flashing all the non-visible forms on shut down (possibly on startup as well? Haven't gotten that far...) which is undesirable.
- Is there another way to get the top and left of the form when it's not visible?
- Alternately, is there a better way to save and restore form state?