There are several ways to do this. Follow an example:
The code below is a Form
whole. I created the same only for testing. Remember to adapt the same with your code that already exists in your Form
:
public partial class Form1 : Form
{
private int _clicks = 1;
private int _originalWidth;
private int _originalHeight;
private Point _originalPosition;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if(_clicks == 1)
{
_originalHeight = Height;
_originalWidth = Width;
_originalPosition = Location;
}
if(_clicks == 2)
{
Width = _originalWidth;
Height = _originalHeight;
Location = _originalPosition;
_clicks = 0;
}
_clicks++;
}
}
- In the first
Click
of Button
, the width, height and position of the Form
are saved.
- In the second
Click
of Button
, the previously saved values are restored and the Form
returns to the same initial dimensions and position. Click counter (_clicks
) is reset and behaves again as if no Click
has been executed.
Not knowing the code makes it harder to help, but it has several ways to do this, the easiest and write this information in json and the second click set of properties with and heigt
– Sérgio Sereno