// // SET AND RECEIVE VALUES public void SetPrevious_View(Special_View xPrevious_View) { Previous_View = xPrevious_View; btnBack.ForeColor = Previous_View.GetColour(); btnBack.FlatAppearance.MouseDownBackColor = System.Drawing.Color.White; btnBack.FlatAppearance.MouseOverBackColor = System.Drawing.Color.White; btnBack.Text = "< " + Previous_View.GetTitle().ToUpper(); btnBack.Visible = true; }
//This method is used to dynamically populate the form with buttons. //Reference on LayoutPanel: https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/walkthrough-arranging-controls-on-windows-forms-using-a-flowlayoutpanel#positioning-controls-using-docking-and-anchoring private void PopulateMenu(List <Type> xAcccessibleViews) { Special_View instance; Buttons = new List <Button>(); for (int i = 0; i < xAcccessibleViews.Count; i++) { //Creating an instance of a view to get its attributes. instance = (Special_View)(Activator.CreateInstance(xAcccessibleViews[i], new object[] { false })); Buttons.Add(new Button()); Buttons[i].Size = new System.Drawing.Size(layoutPanel.Width, 35); Buttons[i].Cursor = System.Windows.Forms.Cursors.Hand; Buttons[i].FlatStyle = System.Windows.Forms.FlatStyle.Flat; Buttons[i].FlatAppearance.BorderSize = 0; Buttons[i].Font = new System.Drawing.Font("Corbel", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); Buttons[i].ForeColor = instance.GetColour(); Buttons[i].Name = "btn" + i.ToString(); Buttons[i].Tag = i; Buttons[i].TabIndex = i; Buttons[i].Text = instance.GetTitle(); Buttons[i].TextAlign = System.Drawing.ContentAlignment.MiddleLeft; //Spacing between buttons Buttons[i].Margin = new Padding(0, 0, 0, 0); layoutPanel.Controls.Add(Buttons[i]); //Special rules for the Logout button. if (i == (xAcccessibleViews.Count - 1)) { Buttons[i].Text = "Logout"; Buttons[i].BackColor = Color.WhiteSmoke; Buttons[i].Margin = new Padding(0, 10, 0, 0); } // Doing the funcitonal button setup //Uniform way of creating the click event Buttons[i].Click -= (sender, e) => { }; Buttons[i].Click += (sender, e) => { Special_View viewInstance = (Special_View)(Activator.CreateInstance(xAcccessibleViews[((Button)sender).TabIndex], new object[] { false })); MenuElement_Changed(new object[] { sender, viewInstance.GetColour() }, e); SetUpButton(e, xAcccessibleViews[((Button)sender).TabIndex], ((Button)sender)); }; } }