There are several ways to do this. Here is an example:
The code below is an integer% with%. I created the same just 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
Form
of Click
, the width, height, and position of Button
are saved.
- In the second% of% of% with%, previously saved values are restored and
Form
returns to the same initial dimensions and the same position. The click counter ( Click
) is reset and behaves as if no Button
has been executed.