private void CloseButton(Button ButtonObject) { MethodInvoker updateIt2 = delegate { ButtonObject.Width = SideMenuPanel.Width; ButtonObject.Text = ""; ButtonObject.ImageAlign = ContentAlignment.MiddleCenter; ButtonObject.Location = new Point(MenuIndicatorPanel.Location.X + 3, ButtonObject.Location.Y); }; MenuIndicatorPanel.BeginInvoke(updateIt2); Application.DoEvents(); }
private void OpenButton(Button ButtonObject, string ButtonName) { MethodInvoker updateIt2 = delegate { Application.DoEvents(); ButtonObject.Width = SideMenuPanel.Width + 5; ButtonObject.Text = ButtonName; ButtonObject.ImageAlign = ContentAlignment.MiddleLeft; ButtonObject.Location = new Point(MenuIndicatorPanel.Location.X + 12, ButtonObject.Location.Y); }; MenuIndicatorPanel.BeginInvoke(updateIt2); }
private void MenuButton_Click(object sender, EventArgs e) { Task ThreadMenu = new Task(() => { //Slow Down Animation When approaching Button. Button[] MenuButtonArray = new Button[] { HomeButton, SearchButton, OrdersButton, adminButton }; // Coppied from Above not making it a Global Variable to prevent any changes if (menuClosed) { while (SideMenuPanel.Width < 139) { Console.WriteLine(SideMenuPanel.Width); MethodInvoker updateIt = delegate { SideMenuPanel.Width = SideMenuPanel.Width + 1; }; SideMenuPanel.BeginInvoke(updateIt); //Add User Control ReSizing Below //Adding a Panel & Then Docking it to the centre removes the need to resize controls as it is handled within the docking. //MethodInvoker UiThread = delegate // { // if (MenuIndicatorPanel.Width > 15) // { // MenuIndicatorPanel.Width += 1; // System.Threading.Thread.Sleep(30); // } // else // { // MenuIndicatorPanel.BackColor = Color.DodgerBlue; // System.Threading.Thread.Sleep(10); // } // }; //MenuIndicatorPanel.BeginInvoke(UiThread); } SideMenuPanel.Size = new Size(139, SideMenuPanel.Height); for (int i = 0; i < 4; i++) { OpenButton(MenuButtonArray[i], MenuButtonNames[i]); } OpenButton(SettingsButton, " Settings"); menuClosed = false; } else { while (SideMenuPanel.Width > CLOSED_PANEL_WDITH) { MethodInvoker updateIt = delegate { SideMenuPanel.Width -= 1; }; SideMenuPanel.BeginInvoke(updateIt); Application.DoEvents(); if (MenuIndicatorPanel.Width != 5) { MethodInvoker updateIt2 = delegate { MenuIndicatorPanel.Width -= 1; }; MenuIndicatorPanel.BeginInvoke(updateIt2); Application.DoEvents(); System.Threading.Thread.Sleep(30); } else { MenuIndicatorPanel.BackColor = Color.Blue; System.Threading.Thread.Sleep(10); } //Add User Control ReSizing Below } menuClosed = true; for (int i = 0; i < 3; i++) { CloseButton(MenuButtonArray[i]); } CloseButton(SettingsButton); } }); ThreadMenu.Start(); }