示例#1
0
文件: ShapeTest.cs 项目: dfr0/moon
			protected override Size MeasureOverride (Size availableSize)
			{
				Tester.WriteLine ("MeasureOverride input = " + availableSize.ToString ());
				Size output = base.MeasureOverride (availableSize);
				Tester.WriteLine ("MeasureOverride output = " + output.ToString ());
				return output;
			}
示例#2
0
文件: ShapeTest.cs 项目: dfr0/moon
			protected override Size ArrangeOverride (Size finalSize)
			{
				Tester.WriteLine ("ArrangeOverride input = " + finalSize.ToString ());
				Size output = base.MeasureOverride (finalSize);
				Tester.WriteLine ("ArrangeOverride output = " +  output.ToString ());
				return output;
			}
        protected override Size MeasureOverride(Size availableSize)
        {
            Debug.WriteLine("GanttItemsPresenter.MeasureOverride(" + availableSize.ToString() + ")");
            for (int i = 0; i < Children.Count; i++)
            {
                GanttItem gi = (GanttItem)Children[i];

                double x1, x2;
                x1 = ParentRow.ParentPanel.ConvertDateToPosition( gi.Section.StartDate );
                x2 = ParentRow.ParentPanel.ConvertDateToPosition( gi.Section.EndDate );
                double width = x2 - x1;

                double x3 = 0d;

                //Gap
                if (gi.Node.ShowGap && i == Children.Count - 1 && ParentRow.RowIndex < ParentRow.ParentPanel.Nodes.Count - 1)
                {
                    IGanttNode nextNode = ParentRow.ParentPanel.Nodes[ParentRow.RowIndex + 1];

                    if (nextNode.StartDate > gi.Node.EndDate && nextNode.ParentNode == gi.Node.ParentNode)
                    {
                        x3 = ParentRow.ParentPanel.ConvertDateToPosition(nextNode.StartDate);
                        width += x3 - x2;
                    }
                }

                if (width < 0)
                    width = 0;

                gi.Measure(new Size(width, ParentRow.ActualHeight));
            }

            return base.MeasureOverride(availableSize);
        }
示例#4
0
 public void DrawRectangle(System.Windows.Point start, System.Windows.Size size, double thickness, bool fill = false)
 {
     m_writer.WriteStartElement("rect");
     m_writer.WriteAttributeString("start", start.ToString(CultureInfo.InvariantCulture));
     m_writer.WriteAttributeString("size", size.ToString(CultureInfo.InvariantCulture));
     m_writer.WriteAttributeString("thickness", thickness.ToString());
     m_writer.WriteAttributeString("fill", fill.ToString());
     m_writer.WriteEndElement();
 }
        protected override Size ArrangeOverride(Size finalSize)
        {
            Debug.WriteLine("GanttRowsPresenter.ArrangeOverride(" + finalSize.ToString() + ")");
            double position = 0d;

            Children.OfType<GanttRow>().ToList<GanttRow>().ForEach(g =>
                {
                    if (g.Visibility == Visibility.Visible)
                    {
                        g.Arrange(new Rect(0d, position, finalSize.Width, ParentPanel.RowHeight));
                        position += ParentPanel.RowHeight;
                    }
                    else
                        g.Arrange(new Rect(0d, 0d, 0d, 0d));
                }
            );

            return base.ArrangeOverride(finalSize);
        }
示例#6
0
 /// <summary>
 /// Arrange
 /// </summary>
 /// <param name="finalSize"></param>
 /// <returns></returns>
 protected override Size ArrangeOverride(Size finalSize)
 {
     ModelItem elem = AdornedElement as ModelItem;
     if (elem == null)
         return finalSize;
     Vector offset = new Vector(thumbs[0].ActualWidth / 2, thumbs[0].ActualHeight / 2);
     Size size = new Size(thumbs[0].ActualWidth, thumbs[0].ActualHeight);
     double halfWidth = elem.Size.Width / 2, halfHeight = elem.Size.Height / 2;
     Point center = new Point(halfWidth, halfHeight) - offset; // center point
     #if DEBUG_ON
     // test value
     System.Console.WriteLine("{0} Size - connItem {1} size {2} hWidth {3} hHeight {4}", System.DateTime.Now.Millisecond, drawingConn, size.ToString(), halfWidth, halfHeight);
     #endif
     thumbs[(int)ConnectorType.Bottom].Arrange(new Rect(center + new Vector(0, halfHeight), size));
     thumbs[(int)ConnectorType.Left].Arrange(new Rect(center + new Vector(-halfWidth, 0), size));
     thumbs[(int)ConnectorType.Center].Arrange(new Rect(center, size));
     thumbs[(int)ConnectorType.Right].Arrange(new Rect(center + new Vector(halfWidth, 0), size));
     thumbs[(int)ConnectorType.Top].Arrange(new Rect(center + new Vector(0, -halfHeight), size));
     return finalSize;
 }
示例#7
0
        public void PerformOperation(object sender, RoutedEventArgs e)
        {
            RadioButton li = sender as RadioButton;

            // Strings used to display results
            String syntaxString, resultType, operationString;

            ///The local variables point1, point2, vector2, etc are defined in each
            ///case block for readability reasons. Each variable is contained within
            ///the scope of each case statement.

            switch (li.Name)
            {   //begin switch
            case "rb1":
            {
                // Translates a Point by a Vector using the overloaded + operator.

                System.Windows.Point point1 = new System.Windows.Point(10, 5);
                Vector vector1 = new Vector(20, 30);
                System.Windows.Point pointResult = new System.Windows.Point();

                pointResult = point1 + vector1;

                // pointResult is equal to (-10,-25)

                // Displaying Results
                syntaxString    = "pointResult = point1 + vector1;";
                resultType      = "Point";
                operationString = "Translating a Point by a Vector";
                ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb2":
            {
                //<Snippet10>
                // Adds a Vector to a Vector using the overloaded + operator.

                Vector vector1      = new Vector(20, 30);
                Vector vector2      = new Vector(45, 70);
                Vector vectorResult = new Vector();


                // vectorResult is equal to (65,100)
                vectorResult = vector1 + vector2;
                //</Snippet10>



                // Displaying Results
                syntaxString    = "vectorResult = vector1 + vector2;";
                resultType      = "Vector";
                operationString = "Adding a Vector to a Vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb3":
            {
                // Adds a Vector to a Vector using the static Add method.

                Vector vector1      = new Vector(20, 30);
                Vector vector2      = new Vector(45, 70);
                Vector vectorResult = new Vector();

                vectorResult = Vector.Add(vector1, vector2);

                // vectorResult is equal to (65,100)

                // Displaying Results
                syntaxString    = "vectorResult = Vector.Add(vector1, vector2);";
                resultType      = "Vector";
                operationString = "Adding a Vector to a Vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb4":
            {
                // Translates a Point by a Vector using the static Add method.

                Vector vector1 = new Vector(20, 30);
                System.Windows.Point point1      = new System.Windows.Point(10, 5);
                System.Windows.Point pointResult = new System.Windows.Point();

                pointResult = Vector.Add(vector1, point1);

                // vectorResult is equal to (30,35)

                // Displaying Results
                syntaxString    = "pointResult = Vector.Add(vector1, point1);";
                resultType      = "Point";
                operationString = "Translating a Point by a Vector";
                ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb5":
            {
                // Subtracts a Vector from a Vector using the overloaded - operator.

                Vector vector1      = new Vector(20, 30);
                Vector vector2      = new Vector(45, 70);
                Vector vectorResult = new Vector();

                vectorResult = vector1 - vector2;

                // vector Result is equal to (-25, -40)

                // Displaying Results
                syntaxString    = "vectorResult = vector1 - vector2;";
                resultType      = "Vector";
                operationString = "Subtracting a Vector from a Vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb6":
            {
                // Subtracts a Vector from a Vector using the static Subtract method.

                Vector vector1      = new Vector(20, 30);
                Vector vector2      = new Vector(45, 70);
                Vector vectorResult = new Vector();

                vectorResult = Vector.Subtract(vector1, vector2);

                // vector Result is equal to (-25, -40)

                // Displaying Results
                syntaxString    = "Vector.Subtract(vector1, vector2);";
                resultType      = "Vector";
                operationString = "Subtracting a Vector from a Vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb7":
            {
                // Multiplies a Vector by a Scalar using the overloaded * operator.

                Vector vector1      = new Vector(20, 30);
                Double scalar1      = 75;
                Vector vectorResult = new Vector();

                vectorResult = vector1 * scalar1;

                // vectorResult is equal to (1500,2250)

                // Displaying Results
                syntaxString    = "vectorResult = vector1 * scalar1;";
                resultType      = "Vector";
                operationString = "Multiplies a Vector by a Scalar";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb8":
            {
                // Multiplies a Scalar by a Vector using the overloaded * operator.

                Vector vector1      = new Vector(20, 30);
                Double scalar1      = 75;
                Vector vectorResult = new Vector();

                vectorResult = scalar1 * vector1;

                // vectorResult is equal to (1500,2250)

                // Displaying Results
                syntaxString    = "vectorResult = scalar1 * vector1;";
                resultType      = "Vector";
                operationString = "Multiplies a Scalar by a Vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb9":
            {
                // Multiplies a Vector by a Vector using the overloaded * operator.

                Vector vector1 = new Vector(20, 30);
                Vector vector2 = new Vector(45, 70);
                Double doubleResult;

                doubleResult = vector1 * vector2;

                // doubleResult is equal to 3000

                // Displaying Results
                syntaxString    = "doubleResult = vector1 * vector2;";
                resultType      = "Double";
                operationString = "Multiplies a Vector by a Vector";
                ShowResults(doubleResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb10":
            {
                // Multiplies a Vector by a Matrix using the overloaded * operator.

                Vector vector1      = new Vector(20, 30);
                Matrix matrix1      = new Matrix(40, 50, 60, 70, 80, 90);
                Vector vectorResult = new Vector();

                vectorResult = vector1 * matrix1;

                // vector Result is equal to (2600,3100)


                // Displaying Results
                syntaxString    = "vectorResult = vector1 * matrix1;";
                resultType      = "Vector";
                operationString = "Multiplies a Vector by a Matrix";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb11":
            {
                // Multiplies a Vector by a Scalar using the static Multiply method.

                Vector vector1      = new Vector(20, 30);
                Double scalar1      = 75;
                Vector vectorResult = new Vector();

                vectorResult = Vector.Multiply(vector1, scalar1);

                // vectorResult is equal to (1500,2250)

                // Displaying Results
                syntaxString    = "vectorResult = Vector.Multiply(vector1, scalar1);";
                resultType      = "Vector";
                operationString = "Multiplies a Vector by a Scalar";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb12":
            {
                // Multiplies a Scalar by a Vector using the static Multiply method.

                Vector vector1      = new Vector(20, 30);
                Double scalar1      = 75;
                Vector vectorResult = new Vector();

                vectorResult = Vector.Multiply(scalar1, vector1);

                // vectorResult is equal to (1500,2250)

                // Displaying Results
                syntaxString    = "vectorResult = Vector.Multiply(scalar1, vector1);";
                resultType      = "Vector";
                operationString = "Multiplies a Scalar by a Vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb13":
            {
                // Multiplies a Vector by a Vector using the static Multiply method.

                Vector vector1 = new Vector(20, 30);
                Vector vector2 = new Vector(45, 70);
                Double doubleResult;

                doubleResult = Vector.Multiply(vector1, vector2);

                // doubleResult is equal to 3000

                // Displaying Results
                syntaxString    = "DoubleResult = Vector.Multiply(vector1,vector2);";
                resultType      = "Double";
                operationString = "Multiplies a Vector by a Vector";
                ShowResults(doubleResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb14":
            {
                // Multiplies a Vector by a Matrix using the static Multiply method.

                Vector vector1      = new Vector(20, 30);
                Matrix matrix1      = new Matrix(40, 50, 60, 70, 80, 90);
                Vector vectorResult = new Vector();

                vectorResult = Vector.Multiply(vector1, matrix1);

                // vector Result is equal to (2600,3100)


                // Displaying Results
                syntaxString    = "vectorResult = Vector.Multiply(vector1,matrix1);";
                resultType      = "Vector";
                operationString = "Multiplies a Vector by a Matrix";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb15":
            {
                // Divides a Vector by a Scalar using the overloaded / operator.

                Vector vector1      = new Vector(20, 30);
                Vector vectorResult = new Vector();
                Double scalar1      = 75;

                vectorResult = vector1 / scalar1;

                // vectorResult is approximately equal to (0.26667,0.4)

                // Displaying Results
                syntaxString    = "vectorResult = vector1 / scalar1;";
                resultType      = "Vector";
                operationString = "Dividing a Vector by a Scalar";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb16":
            {
                // Divides a Vector by a Double using the static Divide method.

                Vector vector1      = new Vector(20, 30);
                Vector vectorResult = new Vector();
                Double scalar1      = 75;

                vectorResult = Vector.Divide(vector1, scalar1);

                // vectorResult is approximately equal to (0.26667,0.4)

                // Displaying Results
                syntaxString    = "vectorResult = Vector.Divide(vector1, scalar1);";
                resultType      = "Vector";
                operationString = "Dividing a Vector by a Scalar";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb17":
            {
                // Gets the hashcode of a Vector structure

                Vector vector1 = new Vector(20, 30);
                int    vectorHashCode;

                vectorHashCode = vector1.GetHashCode();

                // Displaying Results
                syntaxString    = "vectorHashCode = vector1.GetHashCode();";
                resultType      = "int";
                operationString = "Getting the hashcode of a Vector";
                ShowResults(vectorHashCode.ToString(), syntaxString, resultType, operationString);
                break;
            }


            case "rb18":
            {
                // Gets the length of a Vector.

                Vector vector1 = new Vector(20, 30);
                Double length;

                length = vector1.Length;

                // length is approximately equal to 36.0555


                // Displaying Results
                syntaxString    = "length = vector1.Length();";
                resultType      = "Double";
                operationString = "Getting the length of a Vector";
                ShowResults(length.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb19":
            {
                // Gets the square of the length of a Vector.

                Vector vector1 = new Vector(20, 30);
                Double lengthSq;

                lengthSq = vector1.LengthSquared;

                // lengthSq is equal to 1300

                // Displaying Results
                syntaxString    = "lengthSq = vector1.LengthSquared;";
                resultType      = "Double";
                operationString = "Getting the length square of a Vector";
                ShowResults(lengthSq.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb20":
            {
                // Normalizes a Vector using the Normalize method.

                Vector vector1 = new Vector(20, 30);

                vector1.Normalize();

                // vector1 is approximately equal to (0.5547,0.8321)

                // Displaying Results
                syntaxString    = "vector1.Normalize();";
                resultType      = "Vector";
                operationString = "Normalizing a Vector";
                ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb21":
            {
                // Calculates the angle between two Vectors using the static AngleBetween method.

                Vector vector1 = new Vector(20, 30);
                Vector vector2 = new Vector(45, 70);
                Double angleBetween;

                angleBetween = Vector.AngleBetween(vector1, vector2);

                // angleBetween is approximately equal to 0.9548

                // Displaying Results
                syntaxString    = "angleBetween = Vector.AngleBetween(vector1, vector2);";
                resultType      = "Double";
                operationString = "Calculating the angle between two Vectors";
                ShowResults(angleBetween.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb22":
            {
                // Calculates the cross product of two Vectors using the static  CrossProduct method.

                Vector vector1 = new Vector(20, 30);
                Vector vector2 = new Vector(45, 70);
                Double crossProduct;

                crossProduct = Vector.CrossProduct(vector1, vector2);

                // crossProduct is equal to 50

                // Displaying Results
                syntaxString    = "crossProduct = Vector.CrossProduct(vector1,vector2);";
                resultType      = "Double";
                operationString = "Calculating the crossproduct of two Vectors";
                ShowResults(crossProduct.ToString(), syntaxString, resultType, operationString);
                break;
            }



            case "rb23":
            {
                // Calculates the determinant of two Vectors using the static Determinant method.

                Vector vector1 = new Vector(20, 30);
                Vector vector2 = new Vector(45, 70);
                Double determinant;

                determinant = Vector.Determinant(vector1, vector2);

                // determinant is equal to 50

                // Displaying Results
                syntaxString    = "determinant = Vector.Determinant(vector1, vector2);";
                resultType      = "Double";
                operationString = "Calculating the determinant of two Vectors";
                ShowResults(determinant.ToString(), syntaxString, resultType, operationString);
                break;
            }


            case "rb24":
            {
                // Checks if two Vectors are equal using the overloaded equality operator.

                // Declaring vecto1 and initializing x,y values
                Vector vector1 = new Vector(20, 30);

                // Declaring vector2 without initializing x,y values
                Vector vector2 = new Vector();

                // Boolean to hold the result of the comparison
                Boolean areEqual;

                // assigning values to vector2
                vector2.X = 45;
                vector2.Y = 70;

                // Comparing Vectors for equality
                areEqual = (vector1 == vector2);

                // areEqual is False

                // Displaying Results
                syntaxString    = "areEqual = (vector1 == vector2);";
                resultType      = "Boolean";
                operationString = "Checking if two vectors are equal";
                ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                break;
            }


            case "rb25":
            {
                // Checks if two Vectors are equal using the static Equals method.

                Vector  vector1 = new Vector(20, 30);
                Vector  vector2 = new Vector(45, 70);
                Boolean areEqual;

                areEqual = Vector.Equals(vector1, vector2);

                // areEqual is False

                // Displaying Results
                syntaxString    = "areEqual = Vector.Equals(vector1, vector2);";
                resultType      = "Boolean";
                operationString = "Checking if two vectors are equal";
                ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb26":
            {
                // Compares an Object and a Vector for equality using the non-static Equals method.

                Vector  vector1 = new Vector(20, 30);
                Vector  vector2 = new Vector(45, 70);
                Boolean areEqual;

                areEqual = vector1.Equals(vector2);

                // areEqual is False


                // Displaying Results
                syntaxString    = "areEqual = vector1.Equals(vector2);";
                resultType      = "Boolean";
                operationString = "Checking if two vectors are equal";
                ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb27":
            {
                // Converts a string representation of a vector into a Vector structure

                Vector vectorResult = new Vector();

                vectorResult = Vector.Parse("1,3");

                // vectorResult is equal to (1,3)

                // Displaying Results
                syntaxString    = "vectorResult = Vector.Parse(\"1,3\");";
                resultType      = "Vector";
                operationString = "Converting a string into a Vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb28":
            {
                // Checks if two Vectors are not equal using the overloaded inequality operator.

                Vector  vector1 = new Vector(20, 30);
                Vector  vector2 = new Vector(45, 70);
                Boolean areNotEqual;

                areNotEqual = (vector1 != vector2);

                // areNotEqual is True

                // Displaying Results
                syntaxString    = "areNotEqual = (vector1 != vector2);";
                resultType      = "Boolean";
                operationString = "Checking if two points are not equal";
                ShowResults(areNotEqual.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb29":
            {
                // Negates a Vector using the Negate method.

                Vector vector1      = new Vector(20, 30);
                Vector vectorResult = new Vector();

                vector1.Negate();

                // vector1 is equal to (-20, -30)

                // Displaying Results
                syntaxString    = "vector1.Negate();";
                resultType      = "void";
                operationString = "Negating a vector";
                ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb30":
            {
                // Negates a Vector using the overloaded unary negation operator.

                Vector vector1      = new Vector(20, 30);
                Vector vectorResult = new Vector();

                vectorResult = -vector1;

                // vectorResult is equal to (-20, -30)

                // Displaying Results
                syntaxString    = "vectorResult = -vector1;";
                resultType      = "Vector";
                operationString = "Negating a vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb31":
            {
                // Gets a String representation of a Vector structure

                Vector vector1 = new Vector(20, 30);
                String vectorString;

                vectorString = vector1.ToString();

                // vectorString is equal to 10,5

                // Displaying Results
                syntaxString    = "vectorString = vector1.ToString();";
                resultType      = "String";
                operationString = "Getting the string representation of a Vector";
                ShowResults(vectorString.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb32":
            {
                // Explicitly converts a Vector structure into a Size structure
                // Returns a Size.

                Vector vector1            = new Vector(20, 30);
                System.Windows.Size size1 = new System.Windows.Size();

                size1 = (System.Windows.Size)vector1;

                // size1 has a width of 20 and a height of 30

                // Displaying Results
                syntaxString    = "size1 = (Size)vector1;";
                resultType      = "Size";
                operationString = "Expliciting casting a Vector into a Size";
                ShowResults(size1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb33":
            {
                // Explicitly converts a Vector structure into a Point structure
                // Returns a Point.

                Vector vector1 = new Vector(20, 30);
                System.Windows.Point point1 = new System.Windows.Point();

                point1 = (System.Windows.Point)vector1;

                // point1 is equal to (20, 30)

                // Displaying Results
                syntaxString    = "point1 = (Point)vector1;";
                resultType      = "Point";
                operationString = "Expliciting casting a Vector into a Point";
                ShowResults(point1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            // task example.  this case statement is not referenced from the list of radio buttons
            case "rb40":
            {
                // adds two vectors using Add and +

                Vector vector1 = new Vector(20, 30);
                Vector vector2 = new Vector(45, 70);

                vector1 = vector1 + vector2;
                // vector1 is now equal to (65, 100)

                vector1 = Vector.Add(vector1, vector2);
                // vector1 is now equal to (110, 170)

                // Displaying Results
                syntaxString    = "vectorResult = Vector.Negate(vector1);";
                resultType      = "Vector";
                operationString = "Negating a vector";
                ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            default:
                break;
            }   // end switch
        }
示例#8
0
        /// <summary>
        /// Overrides MeasureOverride().
        /// </summary>
        /// <param name="availableSize">The available size.</param>
        /// <returns>Returns the measured size.</returns>
        protected override Size MeasureOverride(Size availableSize)
        {
            Debug.WriteLine("MeasureOverride(availableSize=" + availableSize.ToString() + " )");
            if (childBorder != null)
            {
                if (sizeOriginal.Width == 0) // Make this measurement only once per instance
                {
                    childBorder.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                    sizeOriginal = childBorder.DesiredSize;
                }

                Size desiredSizeMax = sizeOriginal;

                childBorder.Measure(availableSize);
                Size desiredSizeFit = childBorder.DesiredSize;

                Double scalingFactorX = 1.0;
                if (availableSize.Width < desiredSizeFit.Width)
                {
                    scalingFactorX = availableSize.Width / desiredSizeFit.Width;
                }
                else if (availableSize.Width < desiredSizeMax.Width)
                {
                    scalingFactorX = availableSize.Width / desiredSizeMax.Width;
                }

                Double scalingFactorY = 1.0;
                if (availableSize.Height < desiredSizeFit.Height)
                {
                    scalingFactorY = availableSize.Height / desiredSizeFit.Height;
                }
                else if (availableSize.Height < desiredSizeMax.Height)
                {
                    scalingFactorY = availableSize.Height / desiredSizeMax.Height;
                }

                scalingFactor = Math.Min(scalingFactorX, scalingFactorY);

                Debug.WriteLine("scalingFactorX:" + scalingFactorX.ToString(CultureInfo.CurrentCulture));
                Debug.WriteLine("scalingFactorY:" + scalingFactorY.ToString(CultureInfo.CurrentCulture));
                Debug.WriteLine("scalingFactor:" + scalingFactor.ToString(CultureInfo.CurrentCulture));

                 if (Double.IsPositiveInfinity(availableSize.Width) || Double.IsPositiveInfinity(availableSize.Height))
                 {
                    sizeActuallyNeeded = new Size(desiredSizeFit.Width * scalingFactor, desiredSizeFit.Height * scalingFactor);
                 }
                 else
                 {
                    sizeActuallyNeeded = new Size(availableSize.Width / scalingFactor, availableSize.Height / scalingFactor);
                 }
            }

            Debug.WriteLine("MeasureOverride(desiredSize=" + sizeActuallyNeeded.ToString() + " )");
            return sizeActuallyNeeded;
        }
示例#9
0
        /// <summary>
        /// Overrides ArrangeOverride().
        /// </summary>
        /// <param name="finalSize">The final size.</param>
        /// <returns>The returned final size.</returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            Debug.WriteLine("ArrangeOverride(finalSize=" + finalSize.ToString() + " )");

            if (childBorder != null)
            {
                ScaleTransform st = new ScaleTransform();
                st.ScaleX = scalingFactor;
                st.ScaleY = scalingFactor;
                st.CenterX = 0;
                st.CenterY = 0;

                childBorder.RenderTransform = st;

                childBorder.Arrange(new Rect(0, 0, sizeActuallyNeeded.Width, sizeActuallyNeeded.Height));

                Debug.WriteLine("ArrangeOverride(scalingFactor=" + scalingFactor.ToString(CultureInfo.CurrentUICulture) + " )");
            }

            return finalSize;
        }
 private void AlertAboutMeasure(Size size)
 {
     Msg = string.Format("{0}", size.ToString());
 }
        public void PerformOperation(object sender, RoutedEventArgs e)
        {
            RadioButton li = sender as RadioButton;

            // Strings used to display results
            String syntaxString, resultType, operationString;

            ///The local variables point1, point2, vector2, etc are defined in each
            ///case block for readability reasons. Each variable is contained within
            ///the scope of each case statement.

            switch (li.Name)
            {   //begin switch

                case "rb1":
                    {
                        // Translates a Point by a Vector using the overloaded + operator.

                        System.Windows.Point point1 = new System.Windows.Point(10, 5);
                        Vector vector1 = new Vector(20, 30);
                        System.Windows.Point pointResult = new System.Windows.Point();

                        pointResult = point1 + vector1;

                        // pointResult is equal to (-10,-25)

                        // Displaying Results
                        syntaxString = "pointResult = point1 + vector1;";
                        resultType = "Point";
                        operationString = "Translating a Point by a Vector";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb2":
                    {

                        // Adds a Vector to a Vector using the overloaded + operator.

                        Vector vector1 = new Vector(20, 30);
                        Vector vector2 = new Vector(45, 70);
                        Vector vectorResult = new Vector();

                        // vectorResult is equal to (65,100)
                        vectorResult = vector1 + vector2;

                        // Displaying Results
                        syntaxString = "vectorResult = vector1 + vector2;";
                        resultType = "Vector";
                        operationString = "Adding a Vector to a Vector";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb3":
                    {
                        // Adds a Vector to a Vector using the static Add method.

                        Vector vector1 = new Vector(20, 30);
                        Vector vector2 = new Vector(45, 70);
                        Vector vectorResult = new Vector();

                        vectorResult = Vector.Add(vector1, vector2);

                        // vectorResult is equal to (65,100)

                        // Displaying Results
                        syntaxString = "vectorResult = Vector.Add(vector1, vector2);";
                        resultType = "Vector";
                        operationString = "Adding a Vector to a Vector";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb4":
                    {
                        // Translates a Point by a Vector using the static Add method.

                        Vector vector1 = new Vector(20, 30);
                        System.Windows.Point point1 = new System.Windows.Point(10, 5);
                        System.Windows.Point pointResult = new System.Windows.Point();

                        pointResult = Vector.Add(vector1, point1);

                        // vectorResult is equal to (30,35)

                        // Displaying Results
                        syntaxString = "pointResult = Vector.Add(vector1, point1);";
                        resultType = "Point";
                        operationString = "Translating a Point by a Vector";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb5":
                    {
                        // Subtracts a Vector from a Vector using the overloaded - operator.

                        Vector vector1 = new Vector(20, 30);
                        Vector vector2 = new Vector(45, 70);
                        Vector vectorResult = new Vector();

                        vectorResult = vector1 - vector2;

                        // vector Result is equal to (-25, -40)

                        // Displaying Results
                        syntaxString = "vectorResult = vector1 - vector2;";
                        resultType = "Vector";
                        operationString = "Subtracting a Vector from a Vector";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb6":
                    {
                        // Subtracts a Vector from a Vector using the static Subtract method.

                        Vector vector1 = new Vector(20, 30);
                        Vector vector2 = new Vector(45, 70);
                        Vector vectorResult = new Vector();

                        vectorResult = Vector.Subtract(vector1, vector2);

                        // vector Result is equal to (-25, -40)

                        // Displaying Results
                        syntaxString = "Vector.Subtract(vector1, vector2);";
                        resultType = "Vector";
                        operationString = "Subtracting a Vector from a Vector";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }
                case "rb7":
                    {
                        // Multiplies a Vector by a Scalar using the overloaded * operator.

                        Vector vector1 = new Vector(20, 30);
                        Double scalar1 = 75;
                        Vector vectorResult = new Vector();

                        vectorResult = vector1 * scalar1;

                        // vectorResult is equal to (1500,2250)

                        // Displaying Results
                        syntaxString = "vectorResult = vector1 * scalar1;";
                        resultType = "Vector";
                        operationString = "Multiplies a Vector by a Scalar";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb8":
                    {
                        // Multiplies a Scalar by a Vector using the overloaded * operator.

                        Vector vector1 = new Vector(20, 30);
                        Double scalar1 = 75;
                        Vector vectorResult = new Vector();

                        vectorResult = scalar1 * vector1;

                        // vectorResult is equal to (1500,2250)

                        // Displaying Results
                        syntaxString = "vectorResult = scalar1 * vector1;";
                        resultType = "Vector";
                        operationString = "Multiplies a Scalar by a Vector";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }
                case "rb9":
                    {
                        // Multiplies a Vector by a Vector using the overloaded * operator.

                        Vector vector1 = new Vector(20, 30);
                        Vector vector2 = new Vector(45, 70);
                        Double doubleResult;

                        doubleResult = vector1 * vector2;

                        // doubleResult is equal to 3000

                        // Displaying Results
                        syntaxString = "doubleResult = vector1 * vector2;";
                        resultType = "Double";
                        operationString = "Multiplies a Vector by a Vector";
                        ShowResults(doubleResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb10":
                    {
                        // Multiplies a Vector by a Matrix using the overloaded * operator.

                        Vector vector1 = new Vector(20, 30);
                        Matrix matrix1 = new Matrix(40, 50, 60, 70, 80, 90);
                        Vector vectorResult = new Vector();

                        vectorResult = vector1 * matrix1;

                        // vector Result is equal to (2600,3100)

                        // Displaying Results
                        syntaxString = "vectorResult = vector1 * matrix1;";
                        resultType = "Vector";
                        operationString = "Multiplies a Vector by a Matrix";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb11":
                    {
                        // Multiplies a Vector by a Scalar using the static Multiply method.

                        Vector vector1 = new Vector(20, 30);
                        Double scalar1 = 75;
                        Vector vectorResult = new Vector();

                        vectorResult = Vector.Multiply(vector1, scalar1);

                        // vectorResult is equal to (1500,2250)

                        // Displaying Results
                        syntaxString = "vectorResult = Vector.Multiply(vector1, scalar1);";
                        resultType = "Vector";
                        operationString = "Multiplies a Vector by a Scalar";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb12":
                    {
                        // Multiplies a Scalar by a Vector using the static Multiply method.

                        Vector vector1 = new Vector(20, 30);
                        Double scalar1 = 75;
                        Vector vectorResult = new Vector();

                        vectorResult = Vector.Multiply(scalar1, vector1);

                        // vectorResult is equal to (1500,2250)

                        // Displaying Results
                        syntaxString = "vectorResult = Vector.Multiply(scalar1, vector1);";
                        resultType = "Vector";
                        operationString = "Multiplies a Scalar by a Vector";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb13":
                    {
                        // Multiplies a Vector by a Vector using the static Multiply method.

                        Vector vector1 = new Vector(20, 30);
                        Vector vector2 = new Vector(45, 70);
                        Double doubleResult;

                        doubleResult = Vector.Multiply(vector1,vector2);

                        // doubleResult is equal to 3000

                        // Displaying Results
                        syntaxString = "DoubleResult = Vector.Multiply(vector1,vector2);";
                        resultType = "Double";
                        operationString = "Multiplies a Vector by a Vector";
                        ShowResults(doubleResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb14":
                    {
                        // Multiplies a Vector by a Matrix using the static Multiply method.

                        Vector vector1 = new Vector(20, 30);
                        Matrix matrix1 = new Matrix(40, 50, 60, 70, 80, 90);
                        Vector vectorResult = new Vector();

                        vectorResult = Vector.Multiply(vector1,matrix1);

                        // vector Result is equal to (2600,3100)

                        // Displaying Results
                        syntaxString = "vectorResult = Vector.Multiply(vector1,matrix1);";
                        resultType = "Vector";
                        operationString = "Multiplies a Vector by a Matrix";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb15":
                    {
                        // Divides a Vector by a Scalar using the overloaded / operator.

                        Vector vector1 = new Vector(20, 30);
                        Vector vectorResult = new Vector();
                        Double scalar1 = 75;

                        vectorResult = vector1 / scalar1;

                        // vectorResult is approximately equal to (0.26667,0.4)

                        // Displaying Results
                        syntaxString = "vectorResult = vector1 / scalar1;";
                        resultType = "Vector";
                        operationString = "Dividing a Vector by a Scalar";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }
                case "rb16":
                    {
                        // Divides a Vector by a Double using the static Divide method.

                        Vector vector1 = new Vector(20, 30);
                        Vector vectorResult = new Vector();
                        Double scalar1 = 75;

                        vectorResult = Vector.Divide(vector1, scalar1);

                        // vectorResult is approximately equal to (0.26667,0.4)

                        // Displaying Results
                        syntaxString = "vectorResult = Vector.Divide(vector1, scalar1);";
                        resultType = "Vector";
                        operationString = "Dividing a Vector by a Scalar";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb17":
                    {
                        // Gets the hashcode of a Vector structure

                        Vector vector1 = new Vector(20, 30);
                        int vectorHashCode;

                        vectorHashCode = vector1.GetHashCode();

                        // Displaying Results
                        syntaxString = "vectorHashCode = vector1.GetHashCode();";
                        resultType = "int";
                        operationString = "Getting the hashcode of a Vector";
                        ShowResults(vectorHashCode.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb18":
                    {
                        // Gets the length of a Vector.

                        Vector vector1 = new Vector(20, 30);
                        Double length;

                        length = vector1.Length;

                        // length is approximately equal to 36.0555

                        // Displaying Results
                        syntaxString = "length = vector1.Length();";
                        resultType = "Double";
                        operationString = "Getting the length of a Vector";
                        ShowResults(length.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb19":
                    {
                        // Gets the square of the length of a Vector.

                        Vector vector1 = new Vector(20, 30);
                        Double lengthSq;

                        lengthSq = vector1.LengthSquared;

                        // lengthSq is equal to 1300

                        // Displaying Results
                        syntaxString = "lengthSq = vector1.LengthSquared;";
                        resultType = "Double";
                        operationString = "Getting the length square of a Vector";
                        ShowResults(lengthSq.ToString(), syntaxString, resultType, operationString);
                        break;
                    }
                case "rb20":
                    {
                        // Normalizes a Vector using the Normalize method.

                        Vector vector1 = new Vector(20, 30);

                        vector1.Normalize();

                        // vector1 is approximately equal to (0.5547,0.8321)

                        // Displaying Results
                        syntaxString = "vector1.Normalize();";
                        resultType = "Vector";
                        operationString = "Normalizing a Vector";
                        ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb21":
                    {
                        // Calculates the angle between two Vectors using the static AngleBetween method.

                        Vector vector1 = new Vector(20, 30);
                        Vector vector2 = new Vector(45, 70);
                        Double angleBetween;

                        angleBetween = Vector.AngleBetween(vector1, vector2 );

                        // angleBetween is approximately equal to 0.9548

                        // Displaying Results
                        syntaxString = "angleBetween = Vector.AngleBetween(vector1, vector2);";
                        resultType = "Double";
                        operationString = "Calculating the angle between two Vectors";
                        ShowResults(angleBetween.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb22":
                    {
                        // Calculates the cross product of two Vectors using the static  CrossProduct method.

                        Vector vector1 = new Vector(20, 30);
                        Vector vector2 = new Vector(45, 70);
                        Double crossProduct;

                        crossProduct = Vector.CrossProduct(vector1,vector2);

                        // crossProduct is equal to 50

                        // Displaying Results
                        syntaxString = "crossProduct = Vector.CrossProduct(vector1,vector2);";
                        resultType = "Double";
                        operationString = "Calculating the crossproduct of two Vectors";
                        ShowResults(crossProduct.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb23":
                    {
                        // Calculates the determinant of two Vectors using the static Determinant method.

                        Vector vector1 = new Vector(20, 30);
                        Vector vector2 = new Vector(45, 70);
                        Double determinant;

                        determinant = Vector.Determinant(vector1, vector2);

                        // determinant is equal to 50

                        // Displaying Results
                        syntaxString = "determinant = Vector.Determinant(vector1, vector2);";
                        resultType = "Double";
                        operationString = "Calculating the determinant of two Vectors";
                        ShowResults(determinant.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb24":
                    {
                        // Checks if two Vectors are equal using the overloaded equality operator.

                        // Declaring vecto1 and initializing x,y values
                        Vector vector1 = new Vector(20, 30);

                        // Declaring vector2 without initializing x,y values
                        Vector vector2 = new Vector();

                        // Boolean to hold the result of the comparison
                        Boolean areEqual;

                        // assigning values to vector2
                        vector2.X = 45;
                        vector2.Y = 70;

                        // Comparing Vectors for equality
                        areEqual = (vector1 == vector2);

                        // areEqual is False

                        // Displaying Results
                        syntaxString = "areEqual = (vector1 == vector2);";
                        resultType = "Boolean";
                        operationString = "Checking if two vectors are equal";
                        ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb25":
                    {
                        // Checks if two Vectors are equal using the static Equals method.

                        Vector vector1 = new Vector(20, 30);
                        Vector vector2 = new Vector(45, 70);
                        Boolean areEqual;

                        areEqual = Vector.Equals(vector1, vector2);

                        // areEqual is False

                        // Displaying Results
                        syntaxString = "areEqual = Vector.Equals(vector1, vector2);";
                        resultType = "Boolean";
                        operationString = "Checking if two vectors are equal";
                        ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }
                case "rb26":
                    {
                        // Compares an Object and a Vector for equality using the non-static Equals method.

                        Vector vector1 = new Vector(20, 30);
                        Vector vector2 = new Vector(45, 70);
                        Boolean areEqual;

                        areEqual = vector1.Equals(vector2);

                        // areEqual is False

                        // Displaying Results
                        syntaxString = "areEqual = vector1.Equals(vector2);";
                        resultType = "Boolean";
                        operationString = "Checking if two vectors are equal";
                        ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb27":
                    {
                        // Converts a string representation of a vector into a Vector structure

                        Vector vectorResult = new Vector();

                        vectorResult = Vector.Parse("1,3");

                        // vectorResult is equal to (1,3)

                        // Displaying Results
                        syntaxString = "vectorResult = Vector.Parse(\"1,3\");";
                        resultType = "Vector";
                        operationString = "Converting a string into a Vector";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb28":
                    {
                        // Checks if two Vectors are not equal using the overloaded inequality operator.

                        Vector vector1 = new Vector(20, 30);
                        Vector vector2 = new Vector(45, 70);
                        Boolean areNotEqual;

                        areNotEqual = (vector1 != vector2);

                        // areNotEqual is True

                        // Displaying Results
                        syntaxString = "areNotEqual = (vector1 != vector2);";
                        resultType = "Boolean";
                        operationString = "Checking if two points are not equal";
                        ShowResults(areNotEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb29":
                    {
                        // Negates a Vector using the Negate method.

                        Vector vector1 = new Vector(20, 30);
                        Vector vectorResult = new Vector();

                        vector1.Negate();

                        // vector1 is equal to (-20, -30)

                        // Displaying Results
                        syntaxString = "vector1.Negate();";
                        resultType = "void";
                        operationString = "Negating a vector";
                        ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb30":
                    {
                        // Negates a Vector using the overloaded unary negation operator.

                        Vector vector1 = new Vector(20, 30);
                        Vector vectorResult = new Vector();

                        vectorResult = -vector1;

                        // vectorResult is equal to (-20, -30)

                        // Displaying Results
                        syntaxString = "vectorResult = -vector1;";
                        resultType = "Vector";
                        operationString = "Negating a vector";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb31":
                    {
                        // Gets a String representation of a Vector structure

                        Vector vector1 = new Vector(20, 30);
                        String vectorString;

                        vectorString = vector1.ToString();

                        // vectorString is equal to 10,5

                        // Displaying Results
                        syntaxString = "vectorString = vector1.ToString();";
                        resultType = "String";
                        operationString = "Getting the string representation of a Vector";
                        ShowResults(vectorString.ToString(), syntaxString, resultType, operationString);
                        break;
                    }
                case "rb32":
                    {
                        // Explicitly converts a Vector structure into a Size structure
                        // Returns a Size.

                        Vector vector1 = new Vector(20, 30);
                        System.Windows.Size size1 = new System.Windows.Size();

                        size1 = (System.Windows.Size)vector1;

                        // size1 has a width of 20 and a height of 30

                        // Displaying Results
                        syntaxString = "size1 = (Size)vector1;";
                        resultType = "Size";
                        operationString = "Expliciting casting a Vector into a Size";
                        ShowResults(size1.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb33":
                    {
                        // Explicitly converts a Vector structure into a Point structure
                        // Returns a Point.

                        Vector vector1 = new Vector(20, 30);
                        System.Windows.Point point1 = new System.Windows.Point();

                        point1 = (System.Windows.Point)vector1;

                        // point1 is equal to (20, 30)

                        // Displaying Results
                        syntaxString = "point1 = (Point)vector1;";
                        resultType = "Point";
                        operationString = "Expliciting casting a Vector into a Point";
                        ShowResults(point1.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                // task example.  this case statement is not referenced from the list of radio buttons
                case "rb40":
                    {
                        // adds two vectors using Add and +

                        Vector vector1 = new Vector(20, 30);
                        Vector vector2 = new Vector(45, 70);

                        vector1 = vector1 + vector2;
                        // vector1 is now equal to (65, 100)

                        vector1 = Vector.Add(vector1, vector2);
                        // vector1 is now equal to (110, 170)

                        // Displaying Results
                        syntaxString = "vectorResult = Vector.Negate(vector1);";
                        resultType = "Vector";
                        operationString = "Negating a vector";
                        ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                default:
                    break;

            }   // end switch
        }
示例#12
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            Debug.WriteLine("GanttPanel.ArrangeOverride(" + finalSize.ToString() + ")");
            RectangleGeometry r = new RectangleGeometry();
            r.Rect = new Rect(0, 0, finalSize.Width - BorderThickness.Left - BorderThickness.Right,
                finalSize.Height - BorderThickness.Top - BorderThickness.Bottom);
            MainElement.Clip = r;

            if (UIHelpers.IsInDesignModeStatic)
            {
                return base.ArrangeOverride(finalSize);
            }

            GenerateRows(finalSize);

            Size result = base.ArrangeOverride(finalSize);

            return result;
        }
示例#13
0
        // This method performs the Point operations
        public void PerformOperation(object sender, RoutedEventArgs e)
        {
            RadioButton li = sender as RadioButton;

            // Strings used to display the results
            String syntaxString, resultType, operationString;

            // The local variables point1, point2, vector2, etc are defined in each
            // case block for readability reasons. Each variable is contained within
            // the scope of each case statement.
            switch (li.Name)
            {   //begin switch

                case "rb1":
                    {
                        // Translates a Point by a Vector using the overloaded + operator.
                        // Returns a Point.
                        Point point1 = new Point(10, 5);
                        Vector vector1 = new Vector(20, 30);
                        Point pointResult = new Point();

                        pointResult = point1 + vector1;
                        // pointResult is equal to (30, 35)

                        // Note: Adding a Point to a Point is not a legal operation

                        // Displaying Results
                        syntaxString = "pointResult = point1 + vector1;";
                        resultType = "Point";
                        operationString = "Adding a Point and Vector";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb2":
                    {
                        // Translates a Point by a Vector using the static Add method.
                        // Returns a Point.
                        Point point1 = new Point(10, 5);
                        Vector vector1 = new Vector(20, 30);
                        Point pointResult = new Point();

                        pointResult = Point.Add(point1, vector1);
                        // pointResult is equal to (30, 35)

                        // Displaying Results
                        syntaxString = "pointResult = Point.Add(point1, vector1);";
                        resultType = "Point";
                        operationString = "Adding a Point and Vector";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb3":
                    {
                        // Subtracts a Vector from a Point using the overloaded - operator.
                        // Returns a Point.
                        Point point1 = new Point(10, 5);
                        Vector vector1 = new Vector(20, 30);
                        Point pointResult = new Point();

                        pointResult = point1 - vector1;
                        // pointResult is equal to (-10, -25)

                        // Displaying Results
                        syntaxString = "pointResult = point1 - vector1;";
                        resultType = "Point";
                        operationString = "Subtracting a Vector from a Point";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb4":
                    {
                        // Subtracts a Vector from a Point using the static Subtract method.
                        // Returns a Point.
                        Point point1 = new Point(10, 5);
                        Vector vector1 = new Vector(20, 30);
                        Point pointResult = new Point();

                        pointResult = Point.Subtract(point1, vector1);
                        // pointResult is equal to (-10, -25)

                        // Displaying Results
                        syntaxString = "pointResult = Point.Subtract(point1, vector1);";
                        resultType = "Point";
                        operationString = "Subtracting a Vector from a Point";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb5":
                    {
                        // Subtracts a Point from a Point using the overloaded - operator.
                        // Returns a Vector.
                        Point point1 = new Point(10, 5);
                        Point point2 = new Point(15, 40);
                        Vector vectorResult = new Vector();

                        vectorResult = point1 - point2;
                        // vectorResult is equal to (-5, -35)

                        // Displaying Results
                        syntaxString = "vectorResult = point1 - point2;";
                        resultType = "Vector";
                        operationString = "Subtracting a Point from a Point";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb6":
                    {
                        // Subtracts a Point from a Point using the static Subtract method.
                        // Returns a Vector.
                        Point point1 = new Point(10, 5);
                        Point point2 = new Point(15, 40);
                        Vector vectorResult = new Vector();

                        vectorResult = Point.Subtract(point1, point2);
                        // vectorResult is equal to (-5, -35)

                        // Displaying Results
                        syntaxString = "vectorResult = Point.Subtract(point1, point2);";
                        resultType = "Vector";
                        operationString = "Subtracting a Point from a Point";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb7":
                    {
                        // Offsets the X and Y values of a Point.
                        Point point1 = new Point(10, 5);

                        point1.Offset(20, 30);
                        // point1 is equal to (30, 35)

                        // Note: This operation is equivalent to adding a point
                        // to vector with the corresponding X,Y values.

                        // Displaying Results
                        syntaxString = "point1.Offset(20,30);";
                        resultType = "Point";
                        operationString = "Offsetting a Point";
                        ShowResults(point1.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb8":
                    {
                        // Multiplies a Point by a Matrix.
                        // Returns a Point.
                        Point point1 = new Point(10, 5);
                        Point pointResult = new Point();
                        Matrix matrix1 = new Matrix(40, 50, 60, 70, 80, 90);

                        pointResult = point1 * matrix1;
                        // pointResult is equal to (780, 940)

                        // Displaying Results
                        resultType = "Point";
                        syntaxString = "pointResult = point1 * matrix1;";
                        operationString = "Multiplying a Point by a Matrix";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb9":
                    {
                        // Multiplies a Point by a Matrix.
                        // Returns a Point.
                        Point point1 = new Point(10, 5);
                        Point pointResult = new Point();
                        Matrix matrix1 = new Matrix(40, 50, 60, 70, 80, 90);

                        pointResult = Point.Multiply(point1, matrix1);
                        // pointResult is equal to (780, 940)

                        // Displaying Results
                        resultType = "Point";
                        syntaxString = "pointResult = Point.Multiply(point1, matrix1);";
                        operationString = "Multiplying a Point by a Matrix";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb10":
                    {
                        // Checks if two Points are equal using the overloaded equality operator.
                        Point point1 = new Point(10, 5);
                        Point point2 = new Point(15, 40);
                        Boolean areEqual;

                        areEqual = (point1 == point2);
                        // areEqual is False

                        // Displaying Results
                        syntaxString = "areEqual = (point1 == point2);";
                        resultType = "Boolean";
                        operationString = "Checking if two points are equal";
                        ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb11":
                    {
                        // Checks if two Points are equal using the static Equals method.
                        Point point1 = new Point(10, 5);
                        Point point2 = new Point(15, 40);
                        Boolean areEqual;

                        areEqual = Point.Equals(point1, point2);
                        // areEqual is False

                        // Displaying Results
                        syntaxString = "areEqual = Point.Equals(point1, point2);";
                        resultType = "Boolean";
                        operationString = "Checking if two points are equal";
                        ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }
                case "rb12":
                    {
                        // Compares an Object and a Point for equality using the non-static Equals method.
                        Point point1 = new Point(10, 5);
                        Point point2 = new Point(15, 40);
                        Boolean areEqual;

                        areEqual = point1.Equals(point2);
                        // areEqual is False

                        // Displaying Results
                        syntaxString = "areEqual = point1.Equals(point2);";
                        resultType = "Boolean";
                        operationString = "Checking if two points are equal";
                        ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb13":
                    {
                        // Compares an Object and a Vector for equality using the non-static Equals method.
                        Vector vector1 = new Vector(20, 30);
                        Vector vector2 = new Vector(45, 70);
                        Boolean areEqual;

                        areEqual = vector1.Equals(vector2);
                        // areEqual is False

                        // Displaying Results
                        syntaxString = "areEqual = vector1.Equals(vector2);";
                        resultType = "Boolean";
                        operationString = "Checking if two vectors are equal";
                        ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb14":
                    {
                        // Converts a string representation of a point into a Point structure
                        Point pointResult = new Point();

                        pointResult = Point.Parse("1,3");
                        // pointResult is equal to (1, 3)

                        // Displaying Results
                        syntaxString = "pointResult = Point.Parse(\"1,3\");";
                        resultType = "Matrix";
                        operationString = "Converts a string into a Point structure.";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }
                case "rb15":
                    {
                        // Gets a string representation of a Point structure
                        Point point1 = new Point(10, 5);
                        String pointString;

                        pointString = point1.ToString();
                        // pointString is equal to 10,5

                        // Displaying Results
                        syntaxString = "pointString = point1.ToString();";
                        resultType = "String";
                        operationString = "Getting the string representation of a Point";
                        ShowResults(pointString.ToString(), syntaxString, resultType, operationString);
                        break;
                    }
                case "rb16":
                    {
                        // Gets the hashcode of a Point structure

                        Point point1 = new Point(10, 5);
                        int pointHashCode;

                        pointHashCode = point1.GetHashCode();

                        // Displaying Results
                        syntaxString = "pointHashCode = point1.GetHashCode();";
                        resultType = "int";
                        operationString = "Getting the hashcode of Point";
                        ShowResults(pointHashCode.ToString(), syntaxString, resultType, operationString);
                        break;
                    }
                case "rb17":
                    {
                        // Explicitly converts a Point structure into a Size structure
                        // Returns a Size.

                        Point point1 = new Point(10, 5);
                        Size size1 = new Size();

                        size1 = (Size)point1;
                        // size1 has a width of 10 and a height of 5

                        // Displaying Results
                        syntaxString = "size1 = (Size)point1;";
                        resultType = "Size";
                        operationString = "Expliciting casting a Point into a Size";
                        ShowResults(size1.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb18":
                    {
                        // Explicitly converts a Point structure into a Vector structure
                        // Returns a Vector.

                        Point point1 = new Point(10, 5);
                        Vector vector1 = new Vector();

                        vector1 = (Vector)point1;
                        // vector1 is equal to (10,5)

                        // Displaying Results
                        syntaxString = "vector1 = (Vector)point1;";
                        resultType = "Vector";
                        operationString = "Expliciting casting a Point into a Vector";
                        ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                // task example.  Not accessed through radio buttons
                case "rb20":
                    {
                        // Checks if two Points are not equal using the overloaded inequality operator.

                        // Declaring point1 and initializing x,y values
                        Point point1 = new Point(10, 5);

                        // Declaring point2 without initializing x,y values
                        Point point2 = new Point();

                        // Boolean to hold the result of the comparison
                        Boolean areNotEqual;

                        // assigning values to point2
                        point2.X = 15;
                        point2.Y = 40;

                        // checking for inequality
                        areNotEqual = (point1 != point2);

                        // areNotEqual is True

                        // Displaying Results
                        syntaxString = "areNotEqual = (point1 != point2);";
                        resultType = "Boolean";
                        operationString = "Checking if two points are not equal";
                        ShowResults(areNotEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                default:
                    break;

            } //end switch
        }
示例#14
0
 protected override Size MeasureOverride(Size availableSize)
 {
     Debug.WriteLine("MeasureOverride (ListBox): " + availableSize.ToString());
     return base.MeasureOverride(availableSize);
 }
示例#15
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            Debug.WriteLine("GanttRow.ArrangeOverride(" + finalSize.ToString() + ")");
            if (_oldSize != finalSize || _sameSizeCnt != 0)
            {
                if (_oldSize != finalSize)
                    _sameSizeCnt = 1;
                else
                    _sameSizeCnt--;

                _oldSize = finalSize;
                if (Node != null)
                    GenerateItems();
                else
                    ItemsPresenter.Children.Clear();

                ItemsPresenter.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height));
                _oldRetSize = base.ArrangeOverride(finalSize);

                return _oldRetSize;
            }

            return _oldRetSize;
        }
 protected override Size MeasureOverride(Size constraint)
 {
     Debug.WriteLine("MeasureOverride (VirtualizingStackPanel): " + constraint.ToString());
     return base.MeasureOverride(constraint);
 }