Example #1
0
    public static void Main()
    {
        // Create an ArrayList.
        ArrayList myAL = new ArrayList();

        myAL.Add("red");
        myAL.Add("blue");
        myAL.Add("yellow");
        myAL.Add("green");
        myAL.Add("orange");
        myAL.Add("purple");

        // Create a new ROCollection that contains the elements in myAL.
        ROCollection myCol = new ROCollection(myAL);

        // Display the contents of the collection using foreach. This is the preferred method.
        Console.WriteLine("Contents of the collection (using foreach):");
        PrintValues1(myCol);

        // Display the contents of the collection using the enumerator.
        Console.WriteLine("Contents of the collection (using enumerator):");
        PrintValues2(myCol);

        // Display the contents of the collection using the Count property and the Item property.
        Console.WriteLine("Contents of the collection (using Count and Item):");
        PrintIndexAndValues(myCol);

        // Search the collection with Contains and IndexOf.
        Console.WriteLine("Contains yellow: {0}", myCol.Contains("yellow"));
        Console.WriteLine("orange is at index {0}.", myCol.IndexOf("orange"));
        Console.WriteLine();
    }
Example #2
0
    public static void Main()
    {
        // Create an ArrayList.
        ArrayList myAL = new ArrayList();

        myAL.Add("red");
        myAL.Add("blue");
        myAL.Add("yellow");
        myAL.Add("green");
        myAL.Add("orange");
        myAL.Add("purple");

        // Create a new ROCollection that contains the elements in myAL.
        ROCollection myReadOnlyCollection = new ROCollection(myAL);

        // <Snippet2>
        // Get the ICollection interface from the ReadOnlyCollectionBase
        // derived class.
        ICollection myCollection = myReadOnlyCollection;

        lock (myCollection.SyncRoot)
        {
            foreach (object item in myCollection)
            {
                // Insert your code here.
            }
        }
        // </Snippet2>
    }
Example #3
0
 // Uses the foreach statement which hides the complexity of the enumerator.
 // NOTE: The foreach statement is the preferred way of enumerating the contents of a collection.
 public static void PrintValues1(ROCollection myCol)
 {
     foreach (Object obj in myCol)
     {
         Console.WriteLine("   {0}", obj);
     }
     Console.WriteLine();
 }
Example #4
0
 // Uses the Count property and the Item property.
 public static void PrintIndexAndValues(ROCollection myCol)
 {
     for (int i = 0; i < myCol.Count; i++)
     {
         Console.WriteLine("   [{0}]:   {1}", i, myCol[i]);
     }
     Console.WriteLine();
 }
Example #5
0
 // Uses the enumerator.
 // NOTE: The foreach statement is the preferred way of enumerating the contents of a collection.
 public static void PrintValues2(ROCollection myCol)
 {
     System.Collections.IEnumerator myEnumerator = myCol.GetEnumerator();
     while (myEnumerator.MoveNext())
     {
         Console.WriteLine("   {0}", myEnumerator.Current);
     }
     Console.WriteLine();
 }
Example #6
0
        protected override void OnLoad(object sender, EventArgs e)
        {
            WaveProgram = MainWindow.CreateProgram(WaveVertexShader, MainWindow.ColoredFragmentShaderPath);

            _wave = new RenderObject(
                ObjectFactory.Curve(
                    FunctionToCurve((x) => 0f, -_length * 1f, _length * 1f, 1600),
                    Color4.White),
                WaveProgram)
            {
                Scale = new Vector3(Window.Width / _length, 1, 1)
            };

            ///// BUTTONS /////
            _startButton = new RectangularButton(
                new RectangleF(Window.Width / 2f - 75f, -Window.Height / 2f + 15f, 60f, 60f),
                ARectangularInteraction.DefaultLineWidth,
                Color4.Gray,
                Color4.White,
                Window.ColoredProgram);
            _startButton.ButtonPressEvent += (o, a) =>
            {
                _working ^= true;
                _startButton.FillColor = _working ? Color4.Red : Color4.Gray;
            };
            ///////////////////

            ///// CHECKBOX /////
            _timeSlipCheck = new RectangularCheckBox(60f, 60f, 5f, Color4.Black, Color4.White, Color4.Red, Window.ColoredProgram);
            ////////////////////

            ///// CIRCLES /////
            Color4 colorC = new Color4(0xCA, 0xC0, 0x3E, 128);

            _circleL = new RenderObject(ObjectFactory.FilledCircle(20f, colorC), Window.ColoredProgram);
            _circleR = new RenderObject(ObjectFactory.FilledCircle(20f, colorC), Window.ColoredProgram);
            ///////////////////

            Color4 colorL = new Color4(0.5f, 0.5f, 0.2f, 1.0f);

            _ampLines = new ROCollection(new RenderObject[]
            {
                new RenderObject(
                    ObjectFactory.Curve(
                        colorL,
                        new System.Numerics.Vector2(-0.5f * _length, +_amplitude / 0.1f),
                        new System.Numerics.Vector2(+0.5f * _length, +_amplitude / 0.1f)),
                    Window.ColoredProgram),
                new RenderObject(
                    ObjectFactory.Curve(
                        colorL,
                        new System.Numerics.Vector2(-0.5f * _length, -_amplitude / 0.1f),
                        new System.Numerics.Vector2(+0.5f * _length, -_amplitude / 0.1f)),
                    Window.ColoredProgram),
                new RenderObject(
                    ObjectFactory.Curve(
                        new Color4(1f, 1f, 1f, 0.3f),
                        new System.Numerics.Vector2(-0.5f * _length, 0f),
                        new System.Numerics.Vector2(+0.5f * _length, 0f)),
                    Window.ColoredProgram)
            })
            {
                Scale = new Vector3(Window.Width / _length, 1, 1)
            };

            ///// SLIDERS /////
            _freqSlider = new StandardSlider(400, 50, 20, 0, 5f, Color4.LightBlue, Color4.White, Window.ColoredProgram);
            _freqSlider.ValueChangedEvent += (o, ev) =>
            {
                _frequency     = ev.NewValue;
                _freqText.Text = $"f={ev.NewValue:0.000} Hz";
                UniformComponents();
            };
            _speedSlider = new StandardSlider(400, 50, 20, 0, 200, Color4.LightBlue, Color.White, Window.ColoredProgram)
            {
                Value = 100f
            };
            _speedSlider.ValueChangedEvent += (o, ev) =>
            {
                _speed          = ev.NewValue;
                _speedText.Text = $"v={ev.NewValue:000.00} m/s";
                UniformComponents();
            };
            ///////////////////

            ////// TEXTS //////
            string fontName = "Time New Roman";

            _freqText      = new RenderText(25, fontName, "f=0.000 Hz", Color.Transparent, Color.White, Window.TexturedProgram);
            _speedText     = new RenderText(25, fontName, "v=100.00 m/s", Color.Transparent, Color.White, Window.TexturedProgram);
            _lengthText    = new RenderText(25, fontName, "L=100.00 m", Color.Transparent, Color.White, Window.TexturedProgram);
            _timeSlipLabel = new RenderText(10, fontName, "timeslip", Color.Transparent, Color.White, Window.TexturedProgram);
            _startLabel    = new RenderText(10, fontName, "start", Color.Transparent, Color.White, Window.TexturedProgram);
            //////////////////

            UniformComponents();
        }