Пример #1
0
        //TODO: add try to take care of empty lists

        private myControl getMinControl(List <myControl> controls)
        {
            myControl a = null;

            try
            {
                a = controls.OrderBy(c => c.myHeight * c.myWidth).First();
            }
            catch (System.InvalidOperationException)
            {
                Console.WriteLine("Missing control");
            }
            return(a);
        }
Пример #2
0
        private void fromUserControl(object sender, myEventArgs e)
        {
            foreach (Control control in e.arrControls)
            {
                if (control.BackColor == getSelectedColor() && control.GetType().Name == this.Text && getControlShapeType(control) == getSelectedShapeType())
                {
                    controlList.Add(new myControl(control.BackColor, control.GetType(), control.Width, control.Height));
                }
            }

            //TODO: Fix this ugly code
            switch (Min_Max_label.Text)
            {
            case "Min":
                myControl min = getMinControl(controlList);
                if (min == null)
                {
                    MessageBox.Show("No minimum control found");
                    break;
                }


                if (min.myType.Name == "Label")
                {
                    Label newLbl = min.convertToLabel();
                    newLbl.Location = ButtonLabel_MinMax_RectangleSquare_control.Location;
                    Controls.Remove(ButtonLabel_MinMax_RectangleSquare_control);
                    this.Controls.Add(newLbl);
                    newLbl.Visible = true;
                    ButtonLabel_MinMax_RectangleSquare_control = newLbl;
                    controlList.Clear();
                }
                else
                {
                    Button newBtn = min.convertToButton();
                    newBtn.Location = ButtonLabel_MinMax_RectangleSquare_control.Location;
                    Controls.Remove(ButtonLabel_MinMax_RectangleSquare_control);
                    this.Controls.Add(newBtn);
                    newBtn.Visible = true;
                    ButtonLabel_MinMax_RectangleSquare_control = newBtn;
                    controlList.Clear();
                }
                break;

            case "Max":
                myControl max = getMaxControl(controlList);
                if (max == null)
                {
                    MessageBox.Show("No minimum control found");
                    break;
                }
                if (max.myType.Name == "Label")
                {
                    Label newLbl = max.convertToLabel();
                    newLbl.Location = ButtonLabel_MinMax_RectangleSquare_control.Location;
                    Controls.Remove(ButtonLabel_MinMax_RectangleSquare_control);
                    this.Controls.Add(newLbl);
                    newLbl.Visible = true;
                    controlList.Clear();
                }
                else
                {
                    Button newBtn = max.convertToButton();
                    newBtn.Location = ButtonLabel_MinMax_RectangleSquare_control.Location;
                    Controls.Remove(ButtonLabel_MinMax_RectangleSquare_control);
                    this.Controls.Add(newBtn);
                    newBtn.Visible = true;
                    controlList.Clear();
                }
                break;

            default:
                break;
            }
        }