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


C# TextBlock.Measure方法代码示例

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


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

示例1: TextLayout

        protected unsafe override bool TextLayout(textpara_t* text, byte** fontpath)
        {
            TextBlock label = new TextBlock();
            label.Inlines.Add(text->Text);
            label.FontFamily = new FontFamily(text->FontName);
            label.FontSize = text->fontsize;

            switch ((char)text->just)
            {
            case 'l':
                label.TextAlignment = TextAlignment.Left;
                break;

            case 'n':
                label.TextAlignment = TextAlignment.Center;
                break;

            case 'r':
                label.TextAlignment = TextAlignment.Right;
                break;
            }

            label.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            Size desiredSize = label.DesiredSize;
            text->width = desiredSize.Width;
            text->height = desiredSize.Height;
            text->yoffset_centerline = 3;

            return true;
        }
开发者ID:modulexcite,项目名称:WpfGraphing,代码行数:30,代码来源:WpfTextLayoutEngine.cs

示例2: PostInfoDisplay

        public PostInfoDisplay(double textRightEdge,
            double viewRightEdge,
            Geometry newTextGeometry,
            string body)
        {
            if (brush == null)
            {
                brush = new SolidColorBrush(Color.FromArgb(0x20, 0x48, 0x3d, 0x8b));
                brush.Freeze();
                Brush penBrush = new SolidColorBrush(Colors.DarkSlateBlue);
                penBrush.Freeze();
                solidPen = new Pen(penBrush, 0.5);
                solidPen.Freeze();
                dashPen = new Pen(penBrush, 0.5);
                dashPen.DashStyle = DashStyles.Dash;
                dashPen.Freeze();
            }

            this.textGeometry = newTextGeometry;

            TextBlock tb = new TextBlock();
            tb.Text = "Blog Entry: " + body;

            const int MarginWidth = 8;
            this.postGrid = new Grid();
            this.postGrid.RowDefinitions.Add(new RowDefinition());
            this.postGrid.RowDefinitions.Add(new RowDefinition());
            ColumnDefinition cEdge = new ColumnDefinition();
            cEdge.Width = new GridLength(MarginWidth);
            ColumnDefinition cEdge2 = new ColumnDefinition();
            cEdge2.Width = new GridLength(MarginWidth);
            this.postGrid.ColumnDefinitions.Add(cEdge);
            this.postGrid.ColumnDefinitions.Add(new ColumnDefinition());
            this.postGrid.ColumnDefinitions.Add(cEdge2);

            System.Windows.Shapes.Rectangle rect = new System.Windows.Shapes.Rectangle();
            rect.RadiusX = 6;
            rect.RadiusY = 3;
            rect.Fill = brush;
            rect.Stroke = Brushes.DarkSlateBlue;

            Size inf = new Size(double.PositiveInfinity, double.PositiveInfinity);
            tb.Measure(inf);
            this.postGrid.Width = tb.DesiredSize.Width + 2 * MarginWidth;

            Grid.SetColumn(rect, 0);
            Grid.SetRow(rect, 0);
            Grid.SetRowSpan(rect, 1);
            Grid.SetColumnSpan(rect, 3);
            Grid.SetRow(tb, 0);
            Grid.SetColumn(tb, 1);
            this.postGrid.Children.Add(rect);
            this.postGrid.Children.Add(tb);

            Canvas.SetLeft(this.postGrid, Math.Max(viewRightEdge - this.postGrid.Width - 20.0, textRightEdge + 20.0));
            Canvas.SetTop(this.postGrid, textGeometry.GetRenderBounds(solidPen).Top);

            this.Children.Add(this.postGrid);
        }
开发者ID:detroitpro,项目名称:ProStudioSearch,代码行数:59,代码来源:PostInfoDisplay.cs

示例3: SetTooltip

        /// <summary>
        /// Sets the tooltip to the TextBlock only if the entire text does not
        /// fit in the available space (i.e. the TextBlock shows Ellipis at the end)
        /// </summary>
        /// <param name="textBlock">TextBlock object</param>
        private static void SetTooltip(TextBlock textBlock)
        {
            if (textBlock == null)
                return;

            textBlock.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            var width = textBlock.DesiredSize.Width;

            ToolTipService.SetToolTip(textBlock, textBlock.ActualWidth < width ? textBlock.Text : null);
        }
开发者ID:AlfredBr,项目名称:nvmsharp,代码行数:15,代码来源:CoreWindow.xaml.cs

示例4: ComputeAutoTooltip

        /// <summary>
        ///     Assigns the ToolTip for the given TextBlock based on whether the text is trimmed
        /// </summary>
        private static void ComputeAutoTooltip(TextBlock textBlock)
        {
            textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            var width = textBlock.DesiredSize.Width;

            if (textBlock.ActualWidth < width)
            {
                ToolTipService.SetToolTip(textBlock, textBlock.Text);
            }
            else
            {
                ToolTipService.SetToolTip(textBlock, null);
            }
        }
开发者ID:huoxudong125,项目名称:HQF.BlogExporter,代码行数:17,代码来源:TextBlockUtils.cs

示例5: ComputeAutoToolTip

 private static void ComputeAutoToolTip(TextBlock textBlock)
 {
     // It is necessary to call Measure so that the DesiredSize gets updated.
     textBlock.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
     var desiredWidth = textBlock.DesiredSize.Width;
     
     if (textBlock.ActualWidth < desiredWidth)
     {
         ToolTipService.SetToolTip(textBlock, textBlock.Text);
     }
     else
     {
         ToolTipService.SetToolTip(textBlock, null);
     }
 }
开发者ID:electrobreath,项目名称:musicmanager,代码行数:15,代码来源:ToolTipBehavior.cs

示例6: MeasureString

        public static Size MeasureString(string s, int offset)
        {
            if (string.IsNullOrEmpty(s))
            {
                return new Size(0, 0);
            }

            var textBlock = new TextBlock()
            {
                Text = s,
                FontSize = 16
            };

            textBlock.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            return new Size(textBlock.DesiredSize.Width + offset, textBlock.DesiredSize.Height);
        }
开发者ID:dantarion,项目名称:ssf4ae-tools,代码行数:16,代码来源:Util.cs

示例7: CalculateLeftOffset

        public static double CalculateLeftOffset(this ICanvasRange range)
        {
            double offset = 0;

            for (double dy = range.Ymin; dy < range.Ymax; dy += range.YTick)
            {
                TextBlock tb = new TextBlock
                {
                    Text = dy.ToString(),
                    TextAlignment = TextAlignment.Right
                };
                tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));

                if (offset < tb.DesiredSize.Width) offset = tb.DesiredSize.Width;
            }
            return offset + 5;
        }
开发者ID:ouyh18,项目名称:LteTools,代码行数:17,代码来源:ICanvasRange.cs

示例8: StringToBitmapSource

 public static BitmapSource StringToBitmapSource(this string str, int fontSize, System.Windows.Media.Color foreground, System.Windows.Media.Color background)
 {
     TextBlock tbX = new TextBlock();
     tbX.FontFamily = new System.Windows.Media.FontFamily("Consolas");
     tbX.Foreground = new System.Windows.Media.SolidColorBrush(foreground);
     tbX.Background = new System.Windows.Media.SolidColorBrush(background);
     tbX.TextAlignment = TextAlignment.Center;
     tbX.FontSize = fontSize;
     tbX.FontStretch = FontStretches.Normal;
     tbX.FontWeight = FontWeights.Medium;
     tbX.Text = str;
     var size = tbX.MeasureString();
     tbX.Width = size.Width;
     tbX.Height = size.Height;
     tbX.Measure(new Size(size.Width, size.Height));
     tbX.Arrange(new Rect(new Size(size.Width, size.Height)));
     return tbX.ToBitmapSource();
 }
开发者ID:JeremyAnsel,项目名称:helix-toolkit,代码行数:18,代码来源:BitmapExtension.cs

示例9: ComputeAutoTooltip

        private static void ComputeAutoTooltip(TextBlock textBlock)
        {
            textBlock.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            double width = textBlock.DesiredSize.Width;

            if (textBlock.ActualWidth < width)
            {
                var toolBlock = new TextBlock()
                                    {
                                        Text = textBlock.Text,
                                        FontSize = GetAutoTooltipFontSize(textBlock)
                                    };
                ToolTipService.SetToolTip(textBlock, toolBlock);
            }
            else
            {
                ToolTipService.SetToolTip(textBlock, null);
            }
        }
开发者ID:reider-roque,项目名称:Elpis,代码行数:19,代码来源:TextBlockUtils.cs

示例10: GenerateXLabels

        public static void GenerateXLabels(this ICanvasRange range, double leftOffset)
        {
            for (double dx = range.Xmin; dx <= range.Xmax; dx += range.XTick)
            {
                Point pt = range.NormalizePoint(new Point(dx, range.Ymin));
                Line tick = new Line
                {
                    Stroke = Brushes.Black,
                    X1 = pt.X,
                    Y1 = pt.Y,
                    X2 = pt.X,
                    Y2 = pt.Y - 5
                };
                range.ChartCanvas.Children.Add(tick);

                TextBlock tb = new TextBlock { Text = dx.ToString() };
                tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                range.TextCanvas.Children.Add(tb);
                Canvas.SetLeft(tb, leftOffset + pt.X - tb.DesiredSize.Width / 2);
                Canvas.SetTop(tb, pt.Y + 2 + tb.DesiredSize.Height / 2);
            }
        }
开发者ID:ouyh18,项目名称:LteTools,代码行数:22,代码来源:ICanvasRange.cs

示例11: InternalGetSize

        private Size InternalGetSize(char c, double fontSize, bool bold, bool italic)
        {
            var @event = new AutoResetEvent(false);
            var size = new Size();
            ((Action)(() =>
                {
                    var textBlock = new TextBlock
                                    {
                                        Text = Convert.ToString(c),
                                        FontSize = fontSize,
                                        FontFamily = _fontFamily,
                                        FontStyle = italic ? FontStyles.Italic : FontStyles.Normal,
                                        FontWeight = bold ? FontWeights.Bold : FontWeights.Normal
                                    };
                    textBlock.Measure(new Size(1024.0, 1024.0));
                    size = new Size(textBlock.ActualWidth, textBlock.ActualHeight);
                    @event.Set();
                })).OnUIThread();

            @event.WaitOne();
            return size;
        }
开发者ID:karbazol,项目名称:FBReaderCS,代码行数:22,代码来源:FontHelper.cs

示例12: ComputeTrimAndShowToolTip

		/// <summary>
		/// Aprēķina vajadzību pēc uzpeldošā padoma un piešķir to teksta elementam <param name="textBlock"/>.
		/// </summary>
		private static void ComputeTrimAndShowToolTip(TextBlock textBlock) {
			if (textBlock.Text == string.Empty) { textBlock.ToolTip=null; return; } // Neesošs teksts mēdz izmērities lielāks, nekā aizpildīts, tāpēc šeit novērš tukšos taisnstūrus.
			textBlock.Measure(new Size(textBlock.TextWrapping == TextWrapping.Wrap ? textBlock.ActualWidth:Double.PositiveInfinity, Double.PositiveInfinity));
			double measuredDimension, actualDimension;
			if (textBlock.TextWrapping == TextWrapping.Wrap) {
				measuredDimension=textBlock.DesiredSize.Height;
				actualDimension=textBlock.ActualHeight;
			} else {
				measuredDimension=textBlock.DesiredSize.Width;
				actualDimension=textBlock.ActualWidth;
			}

			if (actualDimension < measuredDimension) {
				// Garāku tekstu rāda ilgāk, lai paspēj izlasīt.
				ToolTipService.SetShowDuration(textBlock, Math.Min(textBlock.Text.Length*200, 30000));
				textBlock.ToolTip=new ToolTip {
					Content=textBlock.Text, Style=GetTrimAndShowToolTip(textBlock)
				};
			} else {
				ToolTipService.SetShowDuration(textBlock, 5000);
				textBlock.ToolTip=null;
			}
		}
开发者ID:drdax,项目名称:Radio,代码行数:26,代码来源:Attached.cs

示例13: PrintFixedDocument

        private void PrintFixedDocument()
        {
            PrintDialog dialog;
            if (LoadPrintDialog(out dialog))
            {
                var document = new FixedDocument();
                var page = new FixedPage();
                var t = new TextBlock
                            {
                                FontFamily = font,
                                FontSize = kFontSize,
                                Text = Data.ToString()
                            };
                page.Children.Add(t);
                t.Measure(new Size(document.DocumentPaginator.PageSize.Width, document.DocumentPaginator.PageSize.Width));
                page.Height = t.DesiredSize.Height;
                page.Width = t.DesiredSize.Width;
                var p = new PageContent { Child = page };
                document.Pages.Add(p);

                Print(document, dialog);
            }
        }
开发者ID:sergiosorias,项目名称:terminalzero,代码行数:23,代码来源:DriverTextOnly.cs

示例14: cmdPrint_Click

        private void cmdPrint_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog printDialog = new PrintDialog();
            if (printDialog.ShowDialog() == true)
            {
                // Create the text.
                Run run = new Run("This is a test of the printing functionality in the Windows Presentation Foundation.");

                // Wrap it in a TextBlock.
                TextBlock visual = new TextBlock(run);                
                visual.Margin = new Thickness(15);
                // Allow wrapping to fit the page width.
                visual.TextWrapping = TextWrapping.Wrap;

                // Scale the TextBlock in both dimensions.
                double zoom;
                if (Double.TryParse(txtScale.Text, out zoom))
                {
                    visual.LayoutTransform = new ScaleTransform(zoom / 100, zoom / 100);

                    // Get the size of the page.
                    Size pageSize = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight);
                    // Trigger the sizing of the element.                
                    visual.Measure(pageSize);
                    visual.Arrange(new Rect(0, 0, pageSize.Width, pageSize.Height));

                    // Print the element.
                    printDialog.PrintVisual(visual, "A Scaled Drawing");
                }
                else
                {
                    MessageBox.Show("Invalid scale value.");
                }
            }

        }
开发者ID:ittray,项目名称:LocalDemo,代码行数:36,代码来源:PrintScaledVisual.xaml.cs

示例15: ApplyStyle

        /// <summary>
        /// Draws the chart without data, just the frame
        /// </summary>
        public void ApplyStyle()
        {
            double tolerance = 0.001d;
            Point pt;
            Line gridLine, tick;
            double dx, dy;
            TextBlock tb = new TextBlock();
            Size size = new Size();

            Canvas.SetLeft(this.chartCanvas, leftOffset);
            Canvas.SetBottom(this.chartCanvas, bottomOffset);
            this.chartCanvas.Width = Math.Abs(this.textCanvas.Width - leftOffset - rightOffset);
            this.chartCanvas.Height = Math.Abs(this.textCanvas.Height - bottomOffset);

            Rectangle chartRect = new Rectangle();
            chartRect.Stroke = Brushes.Black;
            chartRect.Fill = Brushes.White;
            chartRect.Width = this.chartCanvas.Width;
            chartRect.Height = this.chartCanvas.Height;
            this.chartCanvas.Children.Add(chartRect);

            // Create vertical gridlines: 
            if (this.drawXGrid)
            {
                for (dx = this.xmin + this.xtickInitDelta; dx + tolerance < this.xmax; dx += this.xtickDelta)
                {
                    gridLine = ChartsHelper.CreateLine(this.lineColor, this.gridLineThickness, this.gridLinePattern);
                    pt = this.NormalizePoint(new Point(dx, this.ymin));
                    gridLine.X1 = pt.X;
                    gridLine.Y1 = pt.Y;
                    pt = this.NormalizePoint(new Point(dx, this.ymax));
                    gridLine.X2 = pt.X;
                    gridLine.Y2 = pt.Y;
                    this.chartCanvas.Children.Add(gridLine);
                }
            }

            // Create horizontal gridlines: 
            if (this.drawYGrid)
            {
                for (dy = this.ymin + this.ytickInitDelta; dy + tolerance < this.ymax; dy += this.ytickDelta)
                {
                    gridLine = ChartsHelper.CreateLine(this.lineColor, this.gridLineThickness, this.gridLinePattern);
                    pt = this.NormalizePoint(new Point(this.xmin, dy));
                    gridLine.X1 = pt.X;
                    gridLine.Y1 = pt.Y;
                    pt = this.NormalizePoint(new Point(this.xmax, dy));
                    gridLine.X2 = pt.X;
                    gridLine.Y2 = pt.Y;
                    this.chartCanvas.Children.Add(gridLine);
                }
            }

            // Create x-axis tick marks
            if (this.drawXTicks)
            {
                for (dx = this.xmin + this.xtickInitDelta; dx + tolerance < this.xmax; dx += this.xtickDelta)
                {
                    pt = NormalizePoint(new Point(dx, this.ymin));
                    tick = ChartsHelper.CreateLine(this.lineColor, this.tickLineThickness, LinePatternEnum.Solid);
                    tick.X1 = pt.X;
                    tick.Y1 = pt.Y;
                    tick.X2 = pt.X;
                    tick.Y2 = pt.Y - this.tickSize;
                    this.chartCanvas.Children.Add(tick);

                    tb = new TextBlock();
                    tb.Text = Math.Round(dx, 3).ToString();
                    tb.Measure(new Size(Double.PositiveInfinity,
                                        Double.PositiveInfinity));
                    size = tb.DesiredSize;
                    this.textCanvas.Children.Add(tb);
                    Canvas.SetLeft(tb, this.leftOffset + pt.X - size.Width / 2.0d);
                    Canvas.SetTop(tb, pt.Y + size.Height / 2.0d);
                }
            }

            // Create y-axis tick marks
            if (this.drawYTicks)
            {
                for (dy = this.ymin + this.ytickInitDelta; dy + tolerance < this.ymax; dy += this.ytickDelta)
                {
                    pt = NormalizePoint(new Point(this.xmin, dy));
                    tick = ChartsHelper.CreateLine(this.lineColor, this.tickLineThickness, LinePatternEnum.Solid);
                    tick.X1 = pt.X;
                    tick.Y1 = pt.Y;
                    tick.X2 = pt.X + this.tickSize;
                    tick.Y2 = pt.Y;
                    this.chartCanvas.Children.Add(tick);

                    tb = new TextBlock();
                    tb.Text = Math.Round(dy, 3).ToString();
                    tb.Measure(new Size(Double.PositiveInfinity,
                                        Double.PositiveInfinity));
                    size = tb.DesiredSize;
                    this.textCanvas.Children.Add(tb);
                    Canvas.SetRight(tb, this.chartCanvas.Width + 10.0d);
//.........这里部分代码省略.........
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:101,代码来源:ChartStyle.cs


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