当前位置: 首页>>代码示例>>C#>>正文


C# TextBlock.MeasureTextSize方法代码示例

本文整理汇总了C#中System.Windows.Controls.TextBlock.MeasureTextSize方法的典型用法代码示例。如果您正苦于以下问题:C# TextBlock.MeasureTextSize方法的具体用法?C# TextBlock.MeasureTextSize怎么用?C# TextBlock.MeasureTextSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.TextBlock的用法示例。


在下文中一共展示了TextBlock.MeasureTextSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PaintCalibration

        /// <summary>
        /// 绘制刻度
        /// </summary>
        /// <param name="size"></param>
        private void PaintCalibration(Size size)
        {
            try
            {
                var width = size.Width;

                var maximum = Maximum;
                var minimum = Minimum;
                var mainScale = MainScale;
                var viceScale = ViceScale;
                var decimalDigits = DecimalDigits;  // 小数点位
                var beginAngle = 1.75d * Math.PI;
                var avgMainAngle = 1.5d * Math.PI / mainScale;
                var avgViceAngle = avgMainAngle / viceScale;
                var avg = (maximum - minimum) / (double)mainScale;
                var fontSize = width * 27d / 518d;

                if (decimalDigits < 0)
                {
                    decimalDigits = 0;
                }
                else if (decimalDigits > 7)
                {
                    decimalDigits = 7;
                }

                _calibrationCanvas.Children.Clear();

                var brush1 = new SolidColorBrush(Colors.Black);
                var brush2 = new SolidColorBrush(Color.FromArgb(0xff, 0x7C, 0x73, 0x63));
                for (int i = 0; i <= mainScale; i++)
                {
                    var mainAngle = beginAngle - avgMainAngle * i;
                    var mainLine = new Line();
                    mainLine.Stroke = brush1;
                    mainLine.StrokeThickness = 2d;
                    mainLine.X1 = width * Math.Sin(mainAngle) * 163d / 518d + width * 0.5d;
                    mainLine.Y1 = width * Math.Cos(mainAngle) * 163d / 518d + width * 0.5d;
                    mainLine.X2 = width * Math.Sin(mainAngle) * 181d / 518d + width * 0.5d;
                    mainLine.Y2 = width * Math.Cos(mainAngle) * 181d / 518d + width * 0.5d;
                    _calibrationCanvas.Children.Add(mainLine);

                    for (int j = 1; j < viceScale && i < mainScale; j++)
                    {
                        var viceAngle = mainAngle - j * avgViceAngle;
                        var viceLine = new Line();
                        viceLine.Stroke = brush2;
                        viceLine.StrokeThickness = 1d;
                        viceLine.X1 = width * Math.Sin(viceAngle) * 163d / 518d + width * 0.5d;
                        viceLine.Y1 = width * Math.Cos(viceAngle) * 163d / 518d + width * 0.5d;
                        viceLine.X2 = width * Math.Sin(viceAngle) * 176d / 518d + width * 0.5d;
                        viceLine.Y2 = width * Math.Cos(viceAngle) * 176d / 518d + width * 0.5d;
                        _calibrationCanvas.Children.Add(viceLine);
                    }

                    var text = new TextBlock();
                    text.FontSize = fontSize;
                    text.Text = Math.Round(minimum + i * avg, decimalDigits).ToString();
                    Size textSize = text.MeasureTextSize();
                    text.SetValue(Canvas.LeftProperty, width * Math.Sin(mainAngle) * 218d / 518d - textSize.Width / 2d + width * 0.5d);
                    text.SetValue(Canvas.TopProperty, width * Math.Cos(mainAngle) * 218d / 518d - textSize.Height / 2d + width * 0.5d);
                    _calibrationCanvas.Children.Add(text);
                }

                PaintPoint(size);
            }
            catch { }
        }
开发者ID:Jitlee,项目名称:WPFMonitor,代码行数:72,代码来源:Meter10.cs

示例2: Paint

        private void Paint(Size finalSize)
        {
            //maxValue = 100;
            var circleWidth = 4d;
            var pointWidth = 4d;
            var keduWidth = 1d;
            var keduLength = 5d;
            var standWidth = 3d;

            var startDegree = 290d;
            var standLength = 10d;
            var minValue = MinValue;
            var maxValue = MaxValue;
            if (minValue >= maxValue)
                return;
            //if (currenValue < minValue || currenValue > maxValue)
            //{
            //    currenValue = (minValue + maxValue) / 2;
            //}
            var widthSpan = 40d;
            var heightSpan = 20d;
            var width = finalSize.Width;
            var height = finalSize.Height;

            if (width < 100d || height < 50d)
            {
                this.Width = width = 100d;
                this.Height = height = 50d;
            }
            var centerX = (width - widthSpan) / 2d + heightSpan;
            var centerY = height - heightSpan + 10d;

            //Single MyWidth, MyHeight;
            //MyWidth = Width - widthSpan;
            //MyHeight = Height - heightSpan;
            //Single DI = 2 * MyHeight;
            //if (MyWidth < MyHeight)
            //{
            //    DI = MyWidth;
            //}

            var degreePerStandKeDu = (720d - 2d * startDegree) / 5d;  //计算出每个标准大刻度之间的角度
            var degreePerKeDu = degreePerStandKeDu / 5d;
            var valuePerKeDu = (maxValue - minValue) / 5;  //每个大刻度之间的值

            //Rectangle MyRect;
            //g = e.Graphics;
            //g.Clear(this.BackColor);
            //g.DrawRectangle(new Pen(Color.Black, 2), 2, 2, this.Width - 4, this.Height - 4);
            _background.SetValue(WidthProperty, width);
            _background.SetValue(HeightProperty, height);

            //MyRect = new Rectangle(0, 0, this.Width, this.Height);
            //g.SmoothingMode = SmoothingMode.AntiAlias;
            ////将绘图平面的坐标原点移到窗口中心
            //g.TranslateTransform(MyWidth / 2 + heightSpan, MyHeight + 10);
            //绘制表盘
            //g.FillEllipse(Brushes.Black,MyRect);
            //string word = currenValue.ToString().Trim() + title;
            //int len = ((word.Trim().Length) * (myFont.Height)) / 2;
            //g.DrawString(word.Trim(), myFont, Brushes.Red, new PointF(-len / 2, -MyHeight / 2 - myFont.Height / 2));
            Size textSize = _text.MeasureTextSize();
            _text.SetValue(Canvas.LeftProperty, centerX - textSize.Width / 2d);
            _text.SetValue(Canvas.TopProperty, centerY - (height - heightSpan - textSize.Height) / 2d);

            //g.RotateTransform(startDegree);
            //绘制刻度标记
            _calibrationCanvas.Children.Clear();
            var calibrationBrush = new SolidColorBrush(Colors.Green);
            _calibrationCanvas.Background = calibrationBrush;
            var calibrationLeft = centerX - 2d;
            var calibrationTop = centerY + 2d - height + heightSpan;
            var calibrationDegree = startDegree;
            var origin = new Point(0.5d, (centerY - calibrationTop) / keduLength);
            for (int x = 0; x < 26; x++)
            {
                //g.FillRectangle(Brushes.Green, new Rectangle(-2, (System.Convert.ToInt16(DI) / 2 - 2) * (-1), keduWidth, keduLength));
                //g.RotateTransform(degreePerKeDu);
                var calibrationLine = new Rectangle();
                calibrationLine.SetValue(Canvas.LeftProperty, calibrationLeft);
                calibrationLine.SetValue(Canvas.TopProperty, calibrationTop);
                calibrationLine.SetValue(WidthProperty, keduWidth);
                calibrationLine.SetValue(HeightProperty, keduLength);
                calibrationLine.Fill = calibrationBrush;
                calibrationLine.RenderTransformOrigin = origin;
                calibrationLine.RenderTransform = new RotateTransform() { Angle = calibrationDegree, };
                _calibrationCanvas.Children.Add(calibrationLine);
                calibrationDegree += degreePerKeDu;
            }
            ////重置绘图平面的坐标变换
            //g.ResetTransform();
            //g.TranslateTransform(MyWidth / 2 + heightSpan, MyHeight + 10);
            //g.RotateTransform(startDegree);
            //mySpeed = minValue;
            ////绘制刻度值
            var speed = minValue;
            var labelBrush = new SolidColorBrush(Colors.Red);
            var lableLineLeft = centerX - 3d;
            var lableLineTop = centerY + 2d - height + heightSpan;
            var labelTop = centerY - (height - heightSpan) + 26d;
//.........这里部分代码省略.........
开发者ID:Jitlee,项目名称:WPFMonitor,代码行数:101,代码来源:DLBiaoPan.cs

示例3: PaintCalibration

        /// <summary>
        /// 绘制刻度
        /// </summary>
        /// <param name="size"></param>
        private void PaintCalibration(Size size)
        {
            try
            {
                var width = size.Width;

                var maximum = Maximum;
                var minimum = Minimum;
                var mainScale = MainScale;
                var viceScale = ViceScale + 1;
                var decimalDigits = DecimalDigits;  // 小数点位
                var beginAngle = 236.25d * Math.PI / 180d;
                var avgMainAngle = 112.5 * Math.PI / (180d * mainScale);
                var avgViceAngle = avgMainAngle / (viceScale);
                var avg = (maximum - minimum) / (double)mainScale;
                var fontSize = width * 36d / 657d;

                if (decimalDigits < 0)
                {
                    decimalDigits = 0;
                }
                else if (decimalDigits > 7)
                {
                    decimalDigits = 7;
                }

                _calibrationCanvas.Children.Clear();

                var brush = new SolidColorBrush(Colors.Black);
                for (int i = 0; i <= mainScale; i++)
                {
                    var mainAngle = beginAngle - avgMainAngle * i;
                    var mainLine = new Line();
                    mainLine.Stroke = brush;
                    mainLine.StrokeThickness = 2d;
                    mainLine.X1 = Math.Sin(mainAngle) * width * 346d / 657d + width * 0.5d;
                    mainLine.Y1 = Math.Cos(mainAngle) * width * 346d / 657d + width * 469d / 657d;
                    mainLine.X2 = Math.Sin(mainAngle) * width * 303d / 657d + width * 0.5d;
                    mainLine.Y2 = Math.Cos(mainAngle) * width * 303d / 657d + width * 469d / 657d;
                    _calibrationCanvas.Children.Add(mainLine);

                    for (int j = 1; j < viceScale && i < mainScale; j++)
                    {
                        var viceAngle = mainAngle - j * avgViceAngle;
                        var viceLine = new Line();
                        viceLine.Stroke = brush;
                        viceLine.StrokeThickness = 1d;
                        viceLine.X1 = Math.Sin(viceAngle) * width * 342d / 657d + width * 0.5d;
                        viceLine.Y1 = Math.Cos(viceAngle) * width * 342d / 657d + width * 469d / 657d;
                        viceLine.X2 = Math.Sin(viceAngle) * width * 303d / 657d + width * 0.5d;
                        viceLine.Y2 = Math.Cos(viceAngle) * width * 303d / 657d + width * 469d / 657d;
                        _calibrationCanvas.Children.Add(viceLine);
                    }

                    var text = new TextBlock();
                    text.FontSize = fontSize;
                    text.Foreground = brush;
                    text.Text = Math.Round(minimum + i * avg, decimalDigits).ToString();
                    Size textSize = text.MeasureTextSize();
                    text.SetValue(Canvas.LeftProperty, Math.Sin(mainAngle) * width * 380d / 657d - textSize.Width / 2d + width * 0.5d);
                    text.SetValue(Canvas.TopProperty, Math.Cos(mainAngle) * width * 380d / 657d - textSize.Height / 2d + width * 469d / 657d);
                    _calibrationCanvas.Children.Add(text);
                }

                PaintPoint(size);
            }
            catch { }
        }
开发者ID:Jitlee,项目名称:WPFMonitor,代码行数:72,代码来源:Meter7.cs

示例4: PaintCalibration

        /// <summary>
        /// 绘制刻度
        /// </summary>
        /// <param name="size"></param>
        private void PaintCalibration(Size size)
        {
            try
            {
                var width = size.Width;

                var maximum = Maximum;
                var minimum = Minimum;
                var mainScale = MainScale;
                var decimalDigits = DecimalDigits;  // 小数点位
                var beginAngle = 1.75d * Math.PI;
                var avgMainAngle = 1.5d * Math.PI / mainScale;
                var avg = (maximum - minimum) / (double)mainScale;
                var fontSize = width * 37d / 633d;

                if (decimalDigits < 0)
                {
                    decimalDigits = 0;
                }
                else if (decimalDigits > 7)
                {
                    decimalDigits = 7;
                }

                _calibrationCanvas.Children.Clear();

                var brush1 = new SolidColorBrush(Colors.Black);
                var brush2 = new SolidColorBrush(Colors.White);
                for (int i = 0; i <= mainScale; i++)
                {
                    var mainAngle = beginAngle - avgMainAngle * i;
                    var mainLine = new Line();
                    mainLine.Stroke = brush1;
                    mainLine.StrokeThickness = 2d;
                    mainLine.X1 = width * Math.Sin(mainAngle) * 222.5d / 633d + width * 0.5d;
                    mainLine.Y1 = width * Math.Cos(mainAngle) * 222.5d / 633d + width * 0.5d;
                    mainLine.X2 = width * Math.Sin(mainAngle) * 197.5d / 633d + width * 0.5d;
                    mainLine.Y2 = width * Math.Cos(mainAngle) * 197.5d / 633d + width * 0.5d;
                    _calibrationCanvas.Children.Add(mainLine);

                    var text = new TextBlock();
                    text.FontSize = fontSize;
                    text.Foreground = brush2;
                    text.Text = Math.Round(minimum + i * avg, decimalDigits).ToString();
                    Size textSize = text.MeasureTextSize();
                    text.SetValue(Canvas.LeftProperty, width * Math.Sin(mainAngle) * 267d / 633d - textSize.Width / 2d + width * 0.5d);
                    text.SetValue(Canvas.TopProperty, width * Math.Cos(mainAngle) * 267d / 633d - textSize.Height / 2d + width * 0.5d);
                    _calibrationCanvas.Children.Add(text);
                }

                PaintPoint(size);
            }
            catch { }
        }
开发者ID:Jitlee,项目名称:WPFMonitor,代码行数:58,代码来源:Meter5.cs


注:本文中的System.Windows.Controls.TextBlock.MeasureTextSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。