示例#1
0
        } // end of CaptionSize

        #endregion

        //--------------------------------------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------------------------------------

        #region SetCaption

        /// <summary>
        /// Autmatically sets a caption above the drawing object
        /// </summary>
        /// <param name="caption">Caption to visualize</param>
        /// <param name="stringAlign">Alignment of caption with respect to drawing object</param>
        public void SetCaption(string caption, CustomStringAlignment stringAlign = CustomStringAlignment.Center)
        {
            GeometryGroup geometryGroup = (GeometryGroup)DrawingShape.Data;

            Point  stringRefPoint = new Point(0, 0);
            double geometryWidth  = 0;

            FormattedText ft = new FormattedText(
                caption,
                Thread.CurrentThread.CurrentCulture,
                System.Windows.FlowDirection.LeftToRight,
                CaptionTypeFace, CaptionSize, new SolidColorBrush(TextColor));

            Geometry stringGeometry = ft.BuildGeometry(new Point());

            if (geometryGroup.Children.Count > 0)
            {
                stringRefPoint = geometryGroup.Bounds.BottomLeft + new Vector(0, stringGeometry.Bounds.Height + CaptionSize);
                geometryWidth  = geometryGroup.Bounds.Width;
            } // end if

            switch (stringAlign)
            {
            case CustomStringAlignment.Left:
                break;

            case CustomStringAlignment.Right:
                stringRefPoint.X += geometryWidth - stringGeometry.Bounds.Width;
                break;

            case CustomStringAlignment.Center:
                stringRefPoint.X += geometryWidth / 2 - stringGeometry.Bounds.Width / 2;
                break;

            default:
                break;
            }

            stringGeometry.Transform = new MatrixTransform(1, 0, 0, -1, stringRefPoint.X, stringRefPoint.Y);

            geometryGroup.Children.Add(stringGeometry);

            _drawingShape.Data = geometryGroup;
        } // end of SetCaption
示例#2
0
        //--------------------------------------------------------------------------------------------------
        // Constructor
        //--------------------------------------------------------------------------------------------------

        #region Constructor

        /// <summary>
        /// Basuc constructor
        /// </summary>
        /// <param name="startPosition">Start position of string</param>
        /// <param name="stringToDraw">The string to visualize</param>
        /// <param name="alignment">Sets the alignment with respect to the position passed</param>
        /// <param name="fontSize">Size of string</param>
        /// <param name="color">Color to display</param>
        /// <param name="typeFaceName">Typface used for string</param>
        public DrawingObjectString(Point startPosition,
                                   string stringToDraw,
                                   CustomStringAlignment alignment,
                                   int fontSize,
                                   Color color,
                                   string typeFaceName = "Arial") : base(startPosition)
        {
            _stringToDraw = stringToDraw;

            _typeFaceName = typeFaceName;
            _fontSize     = fontSize;
            _alignment    = alignment;
            _stringColor  = color;

            DrawingShape.Stroke = new SolidColorBrush(color);
            DrawingShape.Fill   = new SolidColorBrush(color);

            SetStringGeometry();
        } // end of DrawingObject