using AppLauncher.Models; using AppLauncher.Windows.Forms; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using System.Windows.Forms; namespace AppLauncher { public partial class MainForm : AForm { protected int collapsedWidth = 40; protected int expandedWidth = 800; public MainForm() : base() { InitializeComponent(); } protected override void OnShown(EventArgs e) { base.OnShown(e); string jsonfigFilename = Path.ChangeExtension(Application.ExecutablePath, "jsonfig"); if (File.Exists(jsonfigFilename)) { loadSession(jsonfigFilename); } this.Width = flowLayoutPanel1.Width + (flowLayoutPanel1.Left * 2); } public async Task ToggleSize() { if (this.Width > collapsedWidth) { flowLayoutPanel1.Visible = false; titlePanel1.LabelVisible = false; await collapseWindow(collapsedWidth, 6); } else { await expandWindow(expandedWidth, 8); flowLayoutPanel1.Visible = true; titlePanel1.LabelVisible = true; } } protected async Task collapseWindow(int width, int increment = 6) { await Task.Run(() => { while (this.Width > width) { if (this.InvokeRequired) { this.Invoke(new MethodInvoker(() => { this.Width -= increment; })); } else { this.Width -= increment; } Application.DoEvents(); } }); } protected async Task expandWindow(int width, int increment = 8) { await Task.Run(() => { while (this.Width < width) { if (this.InvokeRequired) { this.Invoke(new MethodInvoker(() => { this.Width += increment; //this.Invalidate(); })); } else { this.Width += increment; //this.Invalidate(); } Application.DoEvents(); } }); } private void toolStripMenuItem1_Click(object sender, EventArgs e) { this.TopMost = !this.TopMost; toolStripMenuItem1.Checked = this.TopMost; } private void exitToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } protected void loadSession(string filename) { string sourceCode = File.ReadAllText(filename); if (string.IsNullOrWhiteSpace(sourceCode)) { return; } List rs = JsonConvert.DeserializeObject>(sourceCode); if (rs == null) { return; } int maxWidth = 0; flowLayoutPanel1.Controls.Clear(); foreach (TileGroupModel item in rs) { TileContainer panel = new TileContainer(item); maxWidth = Math.Max(maxWidth, panel.Width); flowLayoutPanel1.Controls.Add(panel); } flowLayoutPanel1.Width = maxWidth; } } }