I’m saving the location of my application but it does not want to keep the value. What happens in the code now is that the _FormClosing is dimmed and “it is never used”. Is there anybody that can see where I go wrong with this code below?
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
if (Settings.Default.WindowLocation != null)
this.Location = Settings.Default.WindowLocation;
this.txtInput60.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress);
}
private void Form1_FormClosing(object sender, FormClosedEventArgs e)
{
Settings.Default.WindowLocation = this.Location;
Settings.Default.Save();
}
private void CheckEnterKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Return)
{
decimal minutes;
decimal.TryParse(txtInput60.Text, out minutes);
if (minutes > 0)
{
var total = (int) (minutes/60*100);
txtOutput100.Text = total.ToString();
Clipboard.SetText(total.ToString());
}
}
}
In my application properties I am setting the WindowLocation with WindowLocation, system.draw.point, user, 0;0
You need to attach the event FormClosing to the method Form1_FormClosing.
This can be done in code of the Form_Load method:
Or by setting the event in the designer
Change the type of the method parameter from FormClosedEventArgs to FormClosingEventArgs: