예제 #1
0
        private void SlowDownClick(object sender, EventArgs e)
        {
            ISlowDown slowDown = (ISlowDown)objectComboBox.SelectedItem;

            slowDown.SlowDown(5);
            panel.GetChildAtPoint(new Point(0, 0)).Text = "Speed: " + slowDown.getSpeed();
        }
예제 #2
0
        private void objectList_SelectedIndexChanged(object sender, EventArgs e)
        {
            label1.Text = objectComboBox.SelectedItem.GetType().Name;
            panel.Controls.Clear();
            panel2.Controls.Clear();

            Type   t            = objectComboBox.SelectedItem.GetType();
            Object selectedItem = objectComboBox.SelectedItem;

            var   interfaces  = t.GetInterfaces();
            int   x           = 0;
            int   y           = 0;
            Point labelPoint  = new Point(x, y);
            Point buttonPoint = new Point(x, y);

            bool isSpeedDisplayed = false;
            bool isHeighDisplayed = false;

            foreach (Type i in interfaces)
            {
                if (i.Equals(typeof(IAccelerate)))
                {
                    IAccelerate iAccelerate = (IAccelerate)selectedItem;

                    if (!isSpeedDisplayed)
                    {
                        CreateLabel("Speed: " + iAccelerate.getSpeed(), labelPoint);
                        isSpeedDisplayed = true;
                        labelPoint.Y    += 25;
                    }
                    Button accelerate = new Button();
                    accelerate.Click   += AccelerateClick;
                    accelerate.Text     = "Accelerate";
                    accelerate.Location = buttonPoint;
                    panel2.Controls.Add(accelerate);
                    buttonPoint.Y += 25;
                }
                else if (i.Equals(typeof(ISlowDown)))
                {
                    ISlowDown iSlowDown = (ISlowDown)selectedItem;
                    if (!isSpeedDisplayed)
                    {
                        CreateLabel("Speed: " + iSlowDown.getSpeed(), labelPoint);
                        isSpeedDisplayed = true;
                        labelPoint.Y    += 25;
                    }

                    Button slowDown = new Button();
                    slowDown.Click   += SlowDownClick;
                    slowDown.Text     = "SlowDown";
                    slowDown.Location = buttonPoint;
                    panel2.Controls.Add(slowDown);
                    buttonPoint.Y += 25;
                }
                else if (i.Equals(typeof(IRise)))
                {
                    IRise iRise = (IRise)selectedItem;
                    if (!isHeighDisplayed)
                    {
                        CreateLabel("Height: " + iRise.getHeight(), labelPoint);
                        isHeighDisplayed = true;
                        labelPoint.Y    += 25;
                    }

                    isHeighDisplayed = true;
                    Button rise = new Button();
                    rise.Click   += RiseClick;
                    rise.Text     = "Rise";
                    rise.Location = buttonPoint;
                    panel2.Controls.Add(rise);
                    buttonPoint.Y += 25;
                }
                else if (i.Equals(typeof(IDive)))
                {
                    IDive iDive = (IDive)selectedItem;
                    if (!isHeighDisplayed)
                    {
                        CreateLabel("Height: " + iDive.getHeight(), labelPoint);
                        isHeighDisplayed = true;
                        labelPoint.Y    += 25;
                    }

                    Button dive = new Button();
                    dive.Click   += DiveClick;
                    dive.Text     = "Dive";
                    dive.Location = buttonPoint;
                    panel2.Controls.Add(dive);
                    buttonPoint.Y += 25;
                }
            }
        }