12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- namespace PictureMover
- {
- public partial class MainForm : Form
- {
- private readonly CoverForm _form2;
- private static readonly string StateFile = Application.ExecutablePath + $".{nameof(MainForm)}.state.txt";
- public MainForm()
- {
- InitializeComponent();
- _form2 = new CoverForm(this);
- }
- private void Form_Shown(object sender, EventArgs e)
- {
- _form2.Show(this);
- Enter += Form_Enter;
- if (File.Exists(StateFile))
- {
- var state = File.ReadAllText(StateFile);
- var pars = state.Split(",")
- .Select(p => int.TryParse(p, out var v) ? (int?)v : null)
- .Where(p => p.HasValue)
- .Select(p => p.Value).ToArray();
- if (pars.Length == 4)
- {
- Left = pars[0];
- Top = pars[1];
- Width = pars[2];
- Height = pars[3];
- }
- }
- FormClosed += MainForm_FormClosed;
- }
- private void MainForm_FormClosed(object? sender, FormClosedEventArgs e)
- {
- var state = $"{Left},{Top},{Width},{Height}";
- File.WriteAllText(StateFile, state);
- }
- private void Form_Enter(object? sender, EventArgs e) => _form2.Focus();
- }
- }
|