tags:

views:

29

answers:

2

Hi,

I have a DataGridView in one of my form which at a certain point I resize an change it's position. I would like to be able to restore it to the designer's default position at runtime. I know I could save it before changing and then restoring it later, but I feel like there surely is a way in .NET to just restore a control position to it's default. Any advice?

+1  A: 

I think the only way is to store the coordinates and the size of the control, then to reapply them to it.

Before moving:

private Point _location;
private Size _size;

private void EventFired(object sender, EventArgs e)
{
    _location = myControl.Location;
    _size = myControl.Size;

    // Move control
}

After moving:

myControl.Location = _location;
myControl.Size = _size;
AS-CII
Thank you for reminding me about the point structure which makes it pretty easy
Ownatik
+1  A: 

There is no such concept as 'default control position'. All controls are positioned from code that is created in InitControls(). To restore 'default position', capture Location rectangle in OnLoad() and restore to that value when needed.

Daniel Mošmondor
Thank you for clearing this out.
Ownatik