コード例 #1
0
        /// <summary>
        /// Adds the label.
        /// </summary>
        /// <param name="labelPath">The label path.</param>
        /// <param name="rect">The rect.</param>
        /// <param name="degrees">The degrees.</param>
        /// <param name="value">The value.</param>
        private void AddLabel(GraphicsPath labelPath, RectangleF rect, double degrees, int value)
        {
            double offset = 0;

            switch (LabelPosition)
            {
            case LabelPosition.Inside:
                offset = -LabelOffset;
                break;

            case LabelPosition.Outside:
                offset = LabelOffset;
                break;
            }

            PointF center = GraphicsHelper.GetPointInArc(rect, degrees, offset);

            using (Bitmap bm = new Bitmap(1, 1))
                using (Graphics g = Graphics.FromImage(bm))
                    using (Font font = new Font(LabelFontFamily, LabelFontSize, LabelFontStyle))
                    {
                        SizeF size = SizeF.Empty;
                        try
                        {
                            size = CustomExtensions.MeasureDisplayStringSize(g, value.ToString(), font);
                        }
                        catch { }

                        PointF origin = new PointF(center.X - (size.Width / 2f),
                                                   center.Y - (size.Height / 2f));
                        labelPath.AddString(value.ToString(), font.FontFamily, (int)font.Style, font.Size,
                                            origin, StringFormat.GenericDefault);
                    }
        }