コード例 #1
0
        private void selectedList_SelectedIndexChanged(object sender, EventArgs e)
        {
            object toy = selectedList.SelectedItem;

            speedLabel.Text    = "0";
            depthLabel.Text    = "0";
            altitudeLabel.Text = "0";

            speedTable.Enabled    = false;
            depthTable.Enabled    = false;
            altitudeTable.Enabled = false;

            if (toy is IAccelerate)
            {
                IAccelerate accelerate = toy as IAccelerate;
                speedLabel.Text    = accelerate.Speed.ToString();
                speedTable.Enabled = true;
            }

            if (toy is IDive)
            {
                IDive dive = toy as IDive;
                depthTable.Text    = dive.Submersion.ToString();
                depthTable.Enabled = true;
            }

            if (toy is IRise)
            {
                IRise rise = toy as IRise;
                altitudeTable.Text    = rise.Altitude.ToString();
                altitudeTable.Enabled = true;
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: patrykxk/C-Sharp-lab1
        private void RiseClick(object sender, EventArgs e)
        {
            IRise irise = (IRise)objectComboBox.SelectedItem;

            irise.Rise(5);
            panel.GetChildAtPoint(new Point(0, 25)).Text = "Height: " + irise.getHeight();
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: Niksior/dotNet
        private void decreaseAltitude_Click(object sender, EventArgs e)
        {
            object toy = toyOwned.SelectedItem;

            IRise altitude = toy as IRise;

            altitude.Rise(altitude.Altitude - 1);

            altitudeValue.Text = altitude.Altitude.ToString();
        }
コード例 #4
0
        private void altitudeUpButton_Click(object sender, EventArgs e)
        {
            object toy = selectedList.SelectedItem;

            IRise rise = toy as IRise;

            rise.Rise(rise.Altitude + 1);

            altitudeLabel.Text = rise.Altitude.ToString();
        }
コード例 #5
0
 public void wyswietlWysokosc()
 {
     foreach (Zabawki zabawka in listaZabawek)
     {
         if (zabawka is IRise)
         {
             IRise wartosc = zabawka as IRise;
             Console.WriteLine(wartosc.GetType().Name + " " + wartosc.wysokosc);
         }
     }
 }
コード例 #6
0
 public void zmienWysokosc(int change)
 {
     foreach (Zabawki zabawka in listaZabawek)
     {
         if (zabawka is IRise)
         {
             IRise wysokosc = zabawka as IRise;
             wysokosc.Rise(change);
         }
     }
 }
コード例 #7
0
 public void setRise(int rise)
 {
     foreach (Zabawka z in zabawki)
     {
         IRise test = z as IRise;
         if (test != null)
         {
             test.Rise = rise;
             Console.WriteLine("Zmiana wzrostu dla zabawki: " + z.Name);
         }
     }
 }
コード例 #8
0
        private void toyInstanceCombo_SelectionChangeCommitted(object sender, EventArgs e)
        {
            controlsPanel.Controls.Clear();
            object toy = toyInstanceCombo.SelectedItem;

            //to wbrew mojej godności
            if (toy is IAccelerate)
            {
                IAccelerate accelerator   = toy as IAccelerate;
                Label       propertyLabel = new Label();
                propertyLabel.Text = "przyśpieszenie";
                NumericUpDown propertySpinner = new NumericUpDown();
                propertySpinner.Value         = accelerator.speed;
                propertySpinner.ValueChanged += new EventHandler(delegate(Object o, EventArgs a)
                {
                    accelerator.Accelerate(Convert.ToInt32(propertySpinner.Value));
                });
                controlsPanel.Controls.Add(propertyLabel);
                controlsPanel.Controls.Add(propertySpinner);
            }

            if (toy is IDive)
            {
                IDive diver         = toy as IDive;
                Label propertyLabel = new Label();
                propertyLabel.Text = "zanurzenie";
                NumericUpDown propertySpinner = new NumericUpDown();
                propertySpinner.Value         = diver.submersion;
                propertySpinner.ValueChanged += new EventHandler(delegate(Object o, EventArgs a)
                {
                    diver.Dive(Convert.ToInt32(propertySpinner.Value));
                });
                controlsPanel.Controls.Add(propertyLabel);
                controlsPanel.Controls.Add(propertySpinner);
            }

            if (toy is IRise)
            {
                IRise         riser           = toy as IRise;
                NumericUpDown propertySpinner = new NumericUpDown();
                Label         propertyLabel   = new Label();
                propertyLabel.Text            = "wzniesienie";
                propertySpinner.Value         = riser.altitude;
                propertySpinner.ValueChanged += new EventHandler(delegate(Object o, EventArgs a)
                {
                    riser.Rise(Convert.ToInt32(propertySpinner.Value));
                });
                controlsPanel.Controls.Add(propertyLabel);
                controlsPanel.Controls.Add(propertySpinner);
            }
        }
コード例 #9
0
 public void pokazZabawki()
 {
     foreach (Zabawka z in zabawki)
     {
         Console.WriteLine("Zabawka: " + z.Name);
         IAccelerate IAtest = z as IAccelerate;
         if (IAtest != null)
         {
             Console.WriteLine("Accelerate: " + IAtest.Accelerate);
         }
         IDive IDtest = z as IDive;
         if (IDtest != null)
         {
             Console.WriteLine("Dive: " + IDtest.Dive);
         }
         IRise IRtest = z as IRise;
         if (IRtest != null)
         {
             Console.WriteLine("Rise: " + IRtest.Rise);
         }
     }
 }
コード例 #10
0
ファイル: Form1.cs プロジェクト: patrykxk/C-Sharp-lab1
        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;
                }
            }
        }