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


C# TextBlock.Arrange方法代码示例

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


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

示例1: 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

示例2: 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

示例3: FindRightFontSize

 public void FindRightFontSize(TextBlock txt,Square block)
 {
     txt.FontSize = 18;
     txt.Measure(new Size(0, 0));
     txt.Arrange(new Rect(0, 0, 0, 0));
     while (txt.ActualHeight > block.Height && txt.FontSize > 13)
     {
         txt.FontSize--;
         txt.Measure(new Size(0, 0));
         txt.Arrange(new Rect(0, 0, 0, 0));
     }
 }
开发者ID:RiedigerD2,项目名称:OpenHouse,代码行数:12,代码来源:TreeMenu.cs

示例4: Text

 private static TextBlock Text(string text, double x, double y)
 {
     var tb = new TextBlock { Text = text, Foreground = Brushes.Black, FontSize = 11 };
     tb.Arrange(new Rect(0, 0, 200, 200));
     tb.SetValue(Canvas.LeftProperty, x - tb.DesiredSize.Width / 2.0);
     tb.SetValue(Canvas.TopProperty, y - tb.DesiredSize.Height / 2.0);
     tb.LayoutTransform = new ScaleTransform(1, -1);
     return tb;
 }
开发者ID:vbodurov,项目名称:space-manager,代码行数:9,代码来源:DimensionPainter.cs

示例5: WhereAmI

        /// <summary>
        /// Initializes a new instance of the <see cref="WhereAmI"/> class.
        /// Creates a square image and attaches an event handler to the layout changed event that
        /// adds the the square in the upper right-hand corner of the TextView via the adornment layer
        /// </summary>
        /// <param name="view">The <see cref="IWpfTextView"/> upon which the adornment will be drawn</param>
        /// <param name="settings">The <see cref="IWhereAmISettings"/> injected by the provider</param>
        public WhereAmI(IWpfTextView view, IWhereAmISettings settings)
        {
            _view = view;
            _settings = settings;

            _fileName = new TextBlock();
            _folderStructure = new TextBlock();
            _projectName = new TextBlock();

            ITextDocument textDoc;
            object obj;
            if (view.TextBuffer.Properties.TryGetProperty<ITextDocument>(typeof(ITextDocument), out textDoc))
            {
                // Retrieved the ITextDocument from the first level
            }
            else if (view.TextBuffer.Properties.TryGetProperty<object>("IdentityMapping", out obj))
            {
                // Try to get the ITextDocument from the second level (e.g. Razor files)
                if ((obj as ITextBuffer) != null)
                {
                    (obj as ITextBuffer).Properties.TryGetProperty<ITextDocument>(typeof(ITextDocument), out textDoc);
                }
            }

            // If I found an ITextDocument, access to its FilePath prop to retrieve informations about Proj
            if (textDoc != null)
            {
                string fileName = System.IO.Path.GetFileName(textDoc.FilePath);

                Project proj = GetContainingProject(fileName);
                if (proj != null)
                {
                    string projectName = proj.Name;

                    if (_settings.ViewFilename)
                    {
                        _fileName.Text = fileName;

                        Brush fileNameBrush = new SolidColorBrush(Color.FromArgb(_settings.FilenameColor.A, _settings.FilenameColor.R, _settings.FilenameColor.G, _settings.FilenameColor.B));
                        _fileName.FontFamily = new FontFamily("Consolas");
                        _fileName.FontSize = _settings.FilenameSize;
                        _fileName.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                        _fileName.TextAlignment = System.Windows.TextAlignment.Right;
                        _fileName.Foreground = fileNameBrush;
                        _fileName.Opacity = _settings.Opacity;
                    }

                    if (_settings.ViewFolders)
                    {
                        _folderStructure.Text = GetFolderDiffs(textDoc.FilePath, proj.FullName);

                        Brush foldersBrush = new SolidColorBrush(Color.FromArgb(_settings.FoldersColor.A, _settings.FoldersColor.R, _settings.FoldersColor.G, _settings.FoldersColor.B));
                        _folderStructure.FontFamily = new FontFamily("Consolas");
                        _folderStructure.FontSize = _settings.FoldersSize;
                        _folderStructure.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                        _folderStructure.TextAlignment = System.Windows.TextAlignment.Right;
                        _folderStructure.Foreground = foldersBrush;
                        _folderStructure.Opacity = _settings.Opacity;
                    }

                    if (_settings.ViewProject)
                    {
                        _projectName.Text = projectName;

                        Brush projectNameBrush = new SolidColorBrush(Color.FromArgb(_settings.ProjectColor.A, _settings.ProjectColor.R, _settings.ProjectColor.G, _settings.ProjectColor.B));
                        _projectName.FontFamily = new FontFamily("Consolas");
                        _projectName.FontSize = _settings.ProjectSize;
                        _projectName.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                        _projectName.TextAlignment = System.Windows.TextAlignment.Right;
                        _projectName.Foreground = projectNameBrush;
                        _projectName.Opacity = _settings.Opacity;
                    }
                }
            }

            // Force to have an ActualWidth
            System.Windows.Rect finalRect = new System.Windows.Rect();
            _fileName.Arrange(finalRect);
            _folderStructure.Arrange(finalRect);
            _projectName.Arrange(finalRect);

            //Grab a reference to the adornment layer that this adornment should be added to
            _adornmentLayer = view.GetAdornmentLayer("WhereAmIAdornment");

            _view.ViewportHeightChanged += delegate { this.onSizeChange(); };
            _view.ViewportWidthChanged += delegate { this.onSizeChange(); };
        }
开发者ID:tanathos,项目名称:WhereAmI2015,代码行数:94,代码来源:WhereAmI.cs

示例6: Convert

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ContentInfo content = value as ContentInfo;


            if (string.IsNullOrEmpty(content.content))
            {
                return new FlowDocument();
            }

            var flowDocument = new FlowDocument();
            var para = new Paragraph();
            TextBlock tb = new TextBlock();
            var str = content.content;
            char surrogate1St = '\0';
            StringBuilder unicodeCodes = new StringBuilder();
            for (int i = 0; i < str.Length; i++)
            {
                int utf16Code = System.Convert.ToInt32(str[i]);
                string hexOutput = String.Format("{0:x}", utf16Code);
                if (surrogate1St != 0)
                {
                    if (utf16Code >= 0xDC00 && utf16Code <= 0xDFFF)
                    {
                        int surrogate2Nd = utf16Code;
                        String unicodeCode = String.Format("{0:x}", (surrogate1St - 0xD800) * (1 << 10) + (1 << 16) + (surrogate2Nd - 0xDC00));
                        unicodeCodes.Append(unicodeCode);

                        if (EmojiStatic.EmojiList.Select(x => x.Key).Any(x => x == ("u" + unicodeCode)))
                        {
                            var bitmap = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "//emoji//u" + unicodeCode + ".png"));
                            var image = new Image
                            {
                                Width = 20,
                                Height = 20,
                                Stretch = Stretch.Uniform,
                                Source = bitmap
                            };

                            //图片缩放模式
                            InlineUIContainer iuc = new InlineUIContainer(image);
                            tb.Inlines.Add(iuc);
                        }
                    }
                    surrogate1St = '\0';
                }
                else if (utf16Code >= 0xD800 && utf16Code <= 0xDBFF)
                {
                    surrogate1St = str[i];
                }
                else
                {
                    tb.Inlines.Add(new Run(str[i].ToString()));
                }
            }

            para.Inlines.Add(new InlineUIContainer(tb));
            flowDocument.Blocks.Add(para);

            // auto sized
            tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            tb.Arrange(new Rect(tb.DesiredSize));

            Debug.WriteLine(tb.ActualWidth); // prints 80.323333333333
            Debug.WriteLine(tb.ActualHeight);// prints 15.96

            flowDocument.PageWidth = tb.ActualWidth;

            return tb.ActualWidth + 30;
        }
开发者ID:GavinHome,项目名称:REVOLUTION,代码行数:70,代码来源:TextMaxWidthConverter.cs

示例7: Update


//.........这里部分代码省略.........
                            double h = rad * (Values[i] - Min) / (Max - Min);
                            double x = xc - rad + (2 * i + 1) * w;
                            double y = yc + rad - h;
                            rectangle = new Rectangle { Width = 2 * w, Height = 2 * h, Fill = brush };
                            rectangle.Tag = new Segment(x, y, w, h, Name, Labels[i]);
                            rectangle.MouseDown += new MouseButtonEventHandler(_ValueClickedEvent);
                            Children.Add(rectangle);
                            Chart.SetLeft(rectangle, x - w);
                            Chart.SetTop(rectangle, y - h);
                        }
                        break;
                }

                brush = new SolidColorBrush(col);
                x1 = x2;
                y1 = y2;

                if (eLegend == Legends.OVERLAY || eLegend == Legends.PERCENT || eLegend == Legends.LEGEND_PERCENT)
                {
                    textblock = new TextBlock
                    {
                        Text = eLegend == Legends.OVERLAY ? Labels[i] : string.Format("{0:F1}%", 100 * Values[i] / Total),
                        Foreground = foreground,
                        FontFamily = fontFamily,
                        FontSize = fontSize,
                        FontWeight = fontWeight,
                        FontStyle = fontStyle
                    };
                    if (bLegendBackground) textblock.Background = brush;
                    textblock.FontSize *= legendScale;
                    textblock.MouseDown += new MouseButtonEventHandler(_ValueClickedEvent);
                    Children.Add(textblock);
                    textblock.Measure(size);
                    textblock.Arrange(new Rect(size));
                    angle -= System.Math.PI * Values[i] / Total;
                    double w = textblock.ActualWidth / 2.0;
                    double h = textblock.ActualHeight / 2.0;
                    if (eStyle == Styles.PIE)
                    {
                        x2 = xc + 0.67 * rad * System.Math.Sin(angle);
                        y2 = yc - 0.67 * rad * System.Math.Cos(angle);
                    }
                    else if (eStyle == Styles.DOUGHNUT)
                    {
                        x2 = xc + (1 + LDChart.DoughnutFraction) / 2.0 * rad * System.Math.Sin(angle);
                        y2 = yc - (1 + LDChart.DoughnutFraction) / 2.0 * rad * System.Math.Cos(angle);
                    }
                    else if (eStyle == Styles.BUBBLE)
                    {
                        double sin = System.Math.Sin(System.Math.PI * Values[i] / Total);
                        double r = rad * sin / (1.0 + sin);
                        x2 = xc + (rad - r) * System.Math.Sin(angle);
                        y2 = yc - (rad - r) * System.Math.Cos(angle);
                    }
                    else if (eStyle == Styles.BAR)
                    {
                        //x2 = xc - rad + rad * (Values[i] - Min) / (Max - Min);
                        x2 = xc - rad + w + 5;
                        y2 = yc - rad + (2 * i + 1) * rad / (double)Count;
                    }
                    else if (eStyle == Styles.COLUMN)
                    {
                        x2 = xc - rad + (2 * i + 1) * rad / (double)Count;
                        //y2 = yc + rad - rad * (Values[i] - Min) / (Max - Min);
                        y2 = yc + rad - w - 5;
                        RotateTransform rotateTransform = new RotateTransform();
开发者ID:litdev1,项目名称:LitDev,代码行数:67,代码来源:Chart.cs

示例8: DrawScale

        /// <summary>
        /// 绘制刻度线
        /// </summary>
        /// <param name="Primary_Radius_Inner">主刻度线内圆半径</param>
        /// <param name="Primary_Radius_Outer">主刻度线外圆半径</param>
        /// <param name="Start_Angle">主刻度线起始角度</param>
        /// <param name="End_Angle">主刻度线终止角度</param>
        /// <param name="Primary_Count">主刻度线数量</param>
        /// <param name="Width">刻度线宽度</param>
        /// <param name="Background">刻度线颜色</param>
        void DrawScale(double Primary_Radius_Inner, double Primary_Radius_Outer, int Primary_Count, double Minor_Radius_Inner, double Minor_Radius_Outer, int Minor_Count, double Start_Angle, double End_Angle, double Width, Brush Background)
        {
            canScale.Children.Clear();
            canPrimaryScaleLabel.Children.Clear();

            if (Primary_Count > 0)
            {
                /* 计算每个Primary Scale标签所显示的数值 */
                double label_interval = (this.Max - this.Min) / Primary_Count;

                /* 计算每个Primary Scale之间的角度 */
                double angle_interval_primary_scale = (End_Angle - Start_Angle) / Primary_Count;

                /* 计算每个Minor Scale之间的角度 */
                double angle_interval_minor_scale = angle_interval_primary_scale / Minor_Count;

                /* 开始绘制 */
                for (int i = 0; i <= Primary_Count; i++)
                {
                    /* 当前要绘制的主刻度的角度值 */
                    double current_angle = Start_Angle + angle_interval_primary_scale * i;

                    /* 绘制主刻度 */
                    Point inner_primary = ShiftedCoordinate(ConvertPolarToDescartes(new Point(Primary_Radius_Inner, current_angle)));
                    Point outer_primary = ShiftedCoordinate(ConvertPolarToDescartes(new Point(Primary_Radius_Outer, current_angle)));
                    Line line_primary = new Line();
                    line_primary.Stroke = Background;
                    line_primary.StrokeThickness = Width;
                    line_primary.X1 = inner_primary.X;
                    line_primary.Y1 = inner_primary.Y;
                    line_primary.X2 = outer_primary.X;
                    line_primary.Y2 = outer_primary.Y;
                    line_primary.SnapsToDevicePixels = true;
                    canScale.Children.Add(line_primary);

                    /* 如果primary scale标签可见,则绘制标签 */
                    if (PrimaryScaleLabelVisibility == Visibility.Visible)
                    {
                        Point poslabel = ShiftedCoordinate(ConvertPolarToDescartes(new Point(PrimaryScaleLabelRadius, Start_Angle + angle_interval_primary_scale * i)));
                        TextBlock label = new TextBlock();
                        label.Text = (this.Min + label_interval * i).ToString("F0");
                        label.SnapsToDevicePixels = true;
                        label.Foreground = this.PrimaryScaleBackground;
                        label.FontFamily = this.FontFamily;
                        label.FontSize = this.FontSize;
                        label.FontStyle = this.FontStyle;
                        label.FontWeight = this.FontWeight;

                        /* 旋转文本 */
                        RotateTransform tr = new RotateTransform(Start_Angle + angle_interval_primary_scale * i + 90);
                        TransformGroup trg = new TransformGroup();
                        trg.Children.Add(tr);
                        label.RenderTransform = trg;
                        label.RenderTransformOrigin = new Point(0.5, 0.5);

                        /* 分析文本宽度和高度,以确定标签应该显示在哪个坐标 */
                        label.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                        label.Arrange(new Rect(label.DesiredSize));
                        Canvas.SetLeft(label, poslabel.X - label.ActualWidth / 2);
                        Canvas.SetTop(label, poslabel.Y - label.ActualHeight / 2);
                        canPrimaryScaleLabel.Children.Add(label);
                    }

                    /* 绘制次刻度
                     * 由于Minor_Count表示的时次刻度将主刻度分割的数量,
                     * 所以当分割数量=1时,不对主刻度做任何分割,所以不予处理
                     * i < PrimaryScaleCount表示绘制完最后一个主刻度以后不再绘制次刻度
                     */
                    if (Minor_Count > 1 && i < PrimaryScaleCount)
                    {
                        for (int n = 1; n < Minor_Count; n++)
                        {
                            Point inner_minor = ShiftedCoordinate(ConvertPolarToDescartes(new Point(Minor_Radius_Inner, current_angle + angle_interval_minor_scale * n)));
                            Point outer_minor = ShiftedCoordinate(ConvertPolarToDescartes(new Point(Minor_Radius_Outer, current_angle + angle_interval_minor_scale * n)));
                            Line line_minor = new Line();
                            line_minor.Stroke = Background;
                            line_minor.StrokeThickness = Width;
                            line_minor.X1 = inner_minor.X;
                            line_minor.Y1 = inner_minor.Y;
                            line_minor.X2 = outer_minor.X;
                            line_minor.Y2 = outer_minor.Y;
                            line_minor.SnapsToDevicePixels = true;
                            canScale.Children.Add(line_minor);
                        }
                    }
                }
            }
        }
开发者ID:35408EF66CCE4377B1E3C2495CA1C18A,项目名称:XuanJiYi_PC,代码行数:98,代码来源:IndicatorMeter.xaml.cs

示例9: LabelItems

		public void LabelItems(Dictionary<object, string> baseObjectToLabel, Dictionary<object, string> baseObjectToLabel2, bool clearLabeling)
		{
			if (clearLabeling)
			{
				this.ClearLabeling();
			}
			this.dictionary_0 = baseObjectToLabel;
			this.dictionary_1 = baseObjectToLabel2;
			Thickness padding = new Thickness(4.0);
			Dictionary<object, TextBlock> dictionary = new Dictionary<object, TextBlock>();
			DropShadowEffect effect = new DropShadowEffect
			{
				BlurRadius = 3.0,
				ShadowDepth = 0.0,
				Opacity = 1.0,
				Color = Colors.White
			};
			int num = 24;
			Size size = new Size(10.0, 10.0);
			Rect finalRect = new Rect(size);
			new SolidColorBrush(Color.FromArgb(128, 128, 0, 128));
			foreach (object current in baseObjectToLabel.Keys)
			{
				TreeItem treeItem = this.treemapHost_0.FindTreeItem(current);
				if (treeItem != null && (treeItem.Bounds.Width >= 70.0 && treeItem.Bounds.Height >= 30.0))
				{
					TextBlock textBlock = new TextBlock
					{
						MaxWidth = treeItem.Bounds.Width,
						MaxHeight = (double)num,
						Foreground = Brushes.Black,
						Text = baseObjectToLabel[current],
						FontWeight = FontWeights.Bold,
						FontSize = 16.0,
						Effect = effect,
						Padding = padding,
						TextWrapping = TextWrapping.NoWrap,
						TextTrimming = TextTrimming.None
					};
					textBlock.Measure(size);
					textBlock.Arrange(finalRect);
					dictionary.Add(current, textBlock);
					Canvas.SetTop(textBlock, treeItem.Bounds.Y);
					Canvas.SetLeft(textBlock, treeItem.Bounds.X);
					this.canvas_2.Children.Add(textBlock);
				}
			}
			foreach (object current in baseObjectToLabel2.Keys)
			{
				TreeItem treeItem = this.treemapHost_0.FindTreeItem(current);
				if (treeItem != null && (treeItem.Bounds.Width >= 50.0 && treeItem.Bounds.Height >= 30.0))
				{
					TextBlock textBlock = new TextBlock
					{
						MaxWidth = treeItem.Bounds.Width,
						Height = 20.0,
						Foreground = Brushes.Black,
						Text = baseObjectToLabel2[current],
						FontSize = 13.0,
						Effect = effect,
						Padding = padding,
						TextWrapping = TextWrapping.NoWrap,
						TextTrimming = TextTrimming.None
					};
					double num2 = treeItem.Bounds.Y;
					if (dictionary.ContainsKey(treeItem.method_0().BaseObject))
					{
						TextBlock textBlock2 = dictionary[treeItem.method_0().BaseObject];
						double num3 = Canvas.GetTop(textBlock2) + textBlock2.ActualHeight;
						if (this.method_0(textBlock2, treeItem.Bounds))
						{
							num2 = num3 - 5.0;
							if (num2 + textBlock.Height > treeItem.Bounds.Bottom)
							{
								continue;
							}
						}
					}
					Canvas.SetTop(textBlock, num2);
					Canvas.SetLeft(textBlock, treeItem.Bounds.X);
					this.canvas_2.Children.Add(textBlock);
				}
			}
		}
开发者ID:akordowski,项目名称:Source-Code-Nitriq,代码行数:84,代码来源:TreemapControl.cs


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