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


C# Media.FormattedText类代码示例

本文整理汇总了C#中System.Windows.Media.FormattedText的典型用法代码示例。如果您正苦于以下问题:C# FormattedText类的具体用法?C# FormattedText怎么用?C# FormattedText使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: DrawHelpText

        /// <summary>
        /// Draw some helpful text.
        /// </summary>
        /// <param name="dc"></param>
        protected virtual void DrawHelpText(DrawingContext dc)
        {
            System.Windows.Media.Typeface backType =
                new System.Windows.Media.Typeface(new System.Windows.Media.FontFamily("sans courier"),
                                                  FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
            System.Windows.Media.FormattedText formatted = new System.Windows.Media.FormattedText(
                                                            "Click & move the mouse to select a capture area.\nENTER/F10: Capture\nBACKSPACE/DEL: Start over\nESC: Exit",
                                                            System.Globalization.CultureInfo.CurrentCulture,
                                                            FlowDirection.LeftToRight,
                                                            backType,
                                                            32.0f,
                                                            new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.White));
            // Make sure the text shows at 0,0 on the primary screen
            System.Drawing.Point primScreen = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Location;
            Point clientBase = PointFromScreen(new Point(primScreen.X + 5, primScreen.Y + 5));
            Geometry textGeo = formatted.BuildGeometry(clientBase);
            dc.DrawGeometry(
                System.Windows.Media.Brushes.White,
                null,
                textGeo);

            dc.DrawGeometry(
                null,
                new System.Windows.Media.Pen(System.Windows.Media.Brushes.White, 1),
                textGeo);
        }
开发者ID:biki3507,项目名称:FreeCapture,代码行数:30,代码来源:CaptureSurface.cs

示例2: DrawPointElement

        protected override void DrawPointElement(DrawingContext dc, int Zoom)
        {
            if (Zoom > 12 || IsMouseOver)
            {
                string postLabelText = string.Format("{0}км", (double)Post.Ordinate / 1000);
                var postLabel = new FormattedText(postLabelText, CultureInfo.CurrentCulture,
                                                  FlowDirection.LeftToRight, new Typeface("Verdana"), 10, mainBrush);

                const int flagHeight = 22;
                dc.PushTransform(new TranslateTransform(0, -flagHeight));

                dc.DrawRectangle(Brushes.White, new Pen(mainBrush, 1), new Rect(-0.5, -0.5, Math.Round(postLabel.Width) + 5, Math.Round(postLabel.Height) + 2));
                dc.DrawText(postLabel, new Point(2, 0));
                dc.DrawLine(new Pen(mainBrush, 2), new Point(0, 0), new Point(0, flagHeight));

                dc.Pop();
            }

            if (Zoom > 8)
                dc.DrawEllipse(SectionBrush, new Pen(mainBrush, 1.5), new Point(0, 0), 5, 5);
            else
                dc.DrawRectangle(SectionBrush, null, new Rect(-2, -2, 4, 4));

            if (IsMouseOver)
            {
                dc.PushTransform(new TranslateTransform(3, 10));
                PrintStack(dc,
                           new FormattedText(Post.Direction == OrdinateDirection.Increasing ? "Возрастает по неч." : "Убывает по неч.",
                                             CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 10, Brushes.DarkBlue),
                           new FormattedText(String.Format("Пути: {0}", string.Join(", ", Post.Tracks.Select(TrackName))),
                                             CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 10, Brushes.DarkOliveGreen));
                dc.Pop();
            }
        }
开发者ID:NpoSaut,项目名称:netEMapTools,代码行数:34,代码来源:KilometerPostMapElement.cs

示例3: CreateText

        /// <summary>
        /// Create the outline geometry based on the formatted text.
        /// </summary>
        public void CreateText()
        {
            FontStyle fontStyle = FontStyles.Normal;
            FontWeight fontWeight = FontWeights.Medium;

            if (Bold == true) fontWeight = FontWeights.Bold;
            if (Italic == true) fontStyle = FontStyles.Italic;

            // Create the formatted text based on the properties set.
            FormattedText formattedText = new FormattedText(
                Text,
                CultureInfo.GetCultureInfo("en-us"),
                FlowDirection.LeftToRight,
                new Typeface(Font, fontStyle, fontWeight, FontStretches.Normal),
                FontSize,
                Brushes.Black // This brush does not matter since we use the geometry of the text. 
                );

            // Build the geometry object that represents the text.
            _textGeometry = formattedText.BuildGeometry(new Point(0, 0));




            //set the size of the custome control based on the size of the text
            this.MinWidth = formattedText.Width;
            this.MinHeight = formattedText.Height;

        }
开发者ID:step4u,项目名称:CallService,代码行数:32,代码来源:OutlinedText.cs

示例4: CalculateIsTextTrimmed

        /// <summary>
        ///     Determines whether or not the text in <paramref name="textBlock" /> is currently being
        ///     trimmed due to width or height constraints.
        /// </summary>
        /// <remarks>Does not work properly when TextWrapping is set to WrapWithOverflow.</remarks>
        /// <param name="textBlock"><see cref="TextBlock" /> to evaluate</param>
        /// <returns><c>true</c> if the text is currently being trimmed; otherwise <c>false</c></returns>
        static bool CalculateIsTextTrimmed(TextBlock textBlock) {
            if (!textBlock.IsArrangeValid)
                return GetIsTextTrimmed(textBlock);

            var typeface = new Typeface(
                textBlock.FontFamily,
                textBlock.FontStyle,
                textBlock.FontWeight,
                textBlock.FontStretch);

            // FormattedText is used to measure the whole width of the text held up by TextBlock container
            var formattedText = new FormattedText(
                textBlock.Text,
                Thread.CurrentThread.CurrentCulture,
                textBlock.FlowDirection,
                typeface,
                textBlock.FontSize,
                textBlock.Foreground) {MaxTextWidth = textBlock.ActualWidth};

            // When the maximum text width of the FormattedText instance is set to the actual
            // width of the textBlock, if the textBlock is being trimmed to fit then the formatted
            // text will report a larger height than the textBlock. Should work whether the
            // textBlock is single or multi-line.
            return formattedText.Height > textBlock.ActualHeight;
        }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:32,代码来源:TextBlockTrimmedTooltip.cs

示例5: Highlight

 public void Highlight(FormattedText text)
 {
     foreach (var item in Rules)
     {
         item.Highlight(text);
     }
 }
开发者ID:JackWangCUMT,项目名称:extensions,代码行数:7,代码来源:Highlighter.cs

示例6: GetTextOrigin

        private static Point GetTextOrigin(ShapeStyle style, ref Rect rect, FormattedText ft)
        {
            double ox, oy;

            switch (style.TextStyle.TextHAlignment)
            {
                case TextHAlignment.Left:
                    ox = rect.TopLeft.X;
                    break;
                case TextHAlignment.Right:
                    ox = rect.Right - ft.Width;
                    break;
                case TextHAlignment.Center:
                default:
                    ox = (rect.Left + rect.Width / 2.0) - (ft.Width / 2.0);
                    break;
            }

            switch (style.TextStyle.TextVAlignment)
            {
                case TextVAlignment.Top:
                    oy = rect.TopLeft.Y;
                    break;
                case TextVAlignment.Bottom:
                    oy = rect.Bottom - ft.Height;
                    break;
                case TextVAlignment.Center:
                default:
                    oy = (rect.Bottom - rect.Height / 2.0) - (ft.Height / 2.0);
                    break;
            }

            return new Point(ox, oy);
        }
开发者ID:Core2D,项目名称:Core2D,代码行数:34,代码来源:WpfRenderer.cs

示例7: OnRender

        /// <summary>
        /// any custom drawing here
        /// </summary>
        /// <param name="drawingContext"></param>
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            if (selectedDirection != null && hasDirection == true)
            {
                //start = DateTime.Now;



                //end = DateTime.Now;
                //delta = (int)(end - start).TotalMilliseconds;

                //FormattedText text = new FormattedText(string.Format(CultureInfo.InvariantCulture, "{0:0.0}", Zoom) + "z, " + MapProvider + ", refresh: " + counter++ + ", load: " + ElapsedMilliseconds + "ms, render: " + delta + "ms", CultureInfo.InvariantCulture, fd, tf, 20, Brushes.Blue);
                //drawingContext.DrawText(text, new Point(text.Height, text.Height));
                //text = null;


                SolidColorBrush brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF072527"));
                FormattedText text = new FormattedText("End location: " + selectedDirection.EndAddress + ".\nStart location: " + selectedDirection.StartAddress + ".\nDistance: " + selectedDirection.Distance + ", duration: " + selectedDirection.Duration, CultureInfo.InvariantCulture, fd, tf, 20, brush);

                SolidColorBrush boxy = new SolidColorBrush(Color.FromArgb(130, 180, 180, 180));
                drawingContext.DrawRectangle(boxy, new Pen(), new Rect(new Point(text.Height, text.Height), new Point(text.Height + text.Width, text.Height * 2)));


                drawingContext.DrawText(text, new Point(text.Height, text.Height));

                text = null;
            }
        }
开发者ID:MatejHrlec,项目名称:OculusView,代码行数:33,代码来源:Map.cs

示例8: BuildFaceModel

        void BuildFaceModel( DrawingContext dc )
        {
            if ( produced ) {
                FormattedText completed_msg = new FormattedText( "Status : Completed", CultureInfo.GetCultureInfo( "ja-JP" ), FlowDirection.LeftToRight, new Typeface( "Georgia" ), 25, Brushes.Green );
                dc.DrawText( completed_msg, new Point( 50, 50 ) );
                return;
            }
            if ( faceModelBuilder == null ) {
                return;
            }
            FaceModelBuilderCollectionStatus collection;
            collection = faceModelBuilder.CollectionStatus;
            if ( collection == 0 ) {
                return;
            }
            //Collection Status
            FormattedText text = new FormattedText( "Status : " + collection.ToString(), CultureInfo.GetCultureInfo( "ja-JP" ), FlowDirection.LeftToRight, new Typeface( "Georgia" ), 25, Brushes.Green );
            dc.DrawText( text, new Point( 50, 50 ) );
            String status = status2string( collection );
            text = new FormattedText( status, CultureInfo.GetCultureInfo( "ja-JP" ), FlowDirection.LeftToRight, new Typeface( "Georgia" ), 25, Brushes.Green );
            dc.DrawText( text, new Point( 50, 80 ) );

            //Capture Status
            FaceModelBuilderCaptureStatus capture;
            capture = faceModelBuilder.CaptureStatus;
            if ( capture == 0 ) {
                return;
            }
            status = status2string( capture );
            text = new FormattedText( status, CultureInfo.GetCultureInfo( "ja-JP" ), FlowDirection.LeftToRight, new Typeface( "Georgia" ), 25, Brushes.Green );
            dc.DrawText( text, new Point( 50, 110 ) );
            return;
        }
开发者ID:noa99kee,项目名称:K4W2-Book,代码行数:33,代码来源:MainWindow.xaml.cs

示例9: escribeTexto

        private void escribeTexto()
        {
            string texto = "";
            FormattedText frmTxt = new FormattedText(texto,
                 CultureInfo.GetCultureInfo("en-us"),
            FlowDirection.LeftToRight, new Typeface("Verdana"), 32, Brushes.Black);
            // Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears.
            frmTxt.MaxTextWidth = 300;
            frmTxt.MaxTextHeight = 240;

            // Use a larger font size beginning at the first (zero-based) character and continuing for 5 characters.
            // The font size is calculated in terms of points -- not as device-independent pixels.
            frmTxt.SetFontSize(36 * (96.0 / 72.0), 0, 5);

            // Use a Bold font weight beginning at the 6th character and continuing for 11 characters.
            frmTxt.SetFontWeight(FontWeights.Bold, 6, 11);

            // Use a linear gradient brush beginning at the 6th character and continuing for 11 characters.
            frmTxt.SetForegroundBrush(
                                    new LinearGradientBrush(
                                    Colors.Orange,
                                    Colors.Teal,
                                    90.0),
                                    6, 11);

            // Use an Italic font style beginning at the 28th character and continuing for 28 characters.
            frmTxt.SetFontStyle(FontStyles.Italic, 28, 28);

            //// Draw the formatted text string to the DrawingContext of the control.
            //drawingContext.DrawText(frmTxt, new Point(10, 0));
        }
开发者ID:amarodev,项目名称:PantallasCC,代码行数:31,代码来源:CuboHorario.xaml.cs

示例10: GetTrimmedPath

        private string GetTrimmedPath(double width)
        {
            if (string.IsNullOrWhiteSpace(Path))
                return string.Empty;

            var filename = System.IO.Path.GetFileName(Path);
            var directory = System.IO.Path.GetDirectoryName(Path);
            bool widthOK;
            var changedWidth = false;

            do
            {
                FormattedText formatted = new FormattedText(
                    string.Format("{0}...\\{1}", directory, filename),
                    CultureInfo.CurrentCulture,
                    FlowDirection.LeftToRight,
                    FontFamily.GetTypefaces().First(),
                    FontSize,
                    Foreground);

                widthOK = formatted.Width < (width * 0.95);

                if (widthOK) continue;

                changedWidth = true;
                if (directory == null) return "...\\" + filename;

                directory = directory.Substring(0, directory.Length - 1);
                if (directory.Length == 0) return "...\\" + filename;
            } while (!widthOK);

            return !changedWidth ? Path : string.Format("{0}...{1}", directory, filename);
        }
开发者ID:lycilph,项目名称:Projects,代码行数:33,代码来源:PathTrimmingTextBlock.cs

示例11: CreateFormattedText

		public static FormattedText CreateFormattedText(ExportText exportText)
		{
			FlowDirection flowDirection;
			
			var culture = CultureInfo.CurrentCulture;
			if (culture.TextInfo.IsRightToLeft) {
				flowDirection = FlowDirection.RightToLeft;
			} else {
				flowDirection = FlowDirection.LeftToRight;
			}
			
			var emSize = ExtensionMethodes.ToPoints((int)exportText.Font.SizeInPoints +1);
			
			var formattedText = new FormattedText(exportText.Text,
				CultureInfo.CurrentCulture,
				flowDirection,
				new Typeface(exportText.Font.FontFamily.Name),
				emSize,
				new SolidColorBrush(exportText.ForeColor.ToWpf()), null, TextFormattingMode.Display);
			
			formattedText.MaxTextWidth = ExtensionMethodes.ToPoints(exportText.DesiredSize.Width);
			
			ApplyPrintStyles(formattedText,exportText);

			return formattedText;
		}
开发者ID:hefnerliu,项目名称:SharpDevelop,代码行数:26,代码来源:FixedDocumentCreator.cs

示例12: UpdateVisual

        /// <summary>
        /// Store <paramref name="timeStamp"/> and updates the text for the visual.
        /// </summary>
        /// <param name="timeStamp">Time of the event.</param>
        /// <param name="line">The line that this time stamp corresponds to.</param>
        /// <param name="view">The <see cref="IWpfTextView"/> to whom the <paramref name="line"/> belongs.</param>
        /// <param name="formatting">Properties for the time stamp text.</param>
        /// <param name="marginWidth">Used to calculate the horizontal offset for <see cref="OnRender(DrawingContext)"/>.</param>
        /// <param name="verticalOffset">Used to calculate the vertical offset for <see cref="OnRender(DrawingContext)"/>.</param>
        /// <param name="showHours">Option to show hours on the time stamp.</param>
        /// <param name="showMilliseconds">Option to show milliseconds on the time stamp.</param>
        internal void UpdateVisual(DateTime timeStamp, ITextViewLine line, IWpfTextView view, TextRunProperties formatting, double marginWidth, double verticalOffset,
                                   bool showHours, bool showMilliseconds)
        {
            this.LineTag = line.IdentityTag;

            if (timeStamp != this.TimeStamp)
            {
                this.TimeStamp = timeStamp;
                string text = GetFormattedTime(timeStamp, showHours, showMilliseconds);
                TextFormattingMode textFormattingMode = view.FormattedLineSource.UseDisplayMode ? TextFormattingMode.Display : TextFormattingMode.Ideal;
                _text = new FormattedText(text, CultureInfo.InvariantCulture, FlowDirection.LeftToRight,
                                          formatting.Typeface, formatting.FontRenderingEmSize, formatting.ForegroundBrush,
                                          InvariantNumberSubstitution, textFormattingMode);

                _horizontalOffset = Math.Round(marginWidth - _text.Width);
                this.InvalidateVisual(); // force redraw
            }

            double newVerticalOffset = line.TextTop - view.ViewportTop + verticalOffset;
            if (newVerticalOffset != _verticalOffset)
            {
                _verticalOffset = newVerticalOffset;
                this.InvalidateVisual(); // force redraw
            }
        }
开发者ID:xornand,项目名称:VS-PPT,代码行数:36,代码来源:TimeStampVisual.cs

示例13: Window_Loaded

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            const int TextFontSize = 30;

               // Make a System.Windows.Media.FormattedText object.
            FormattedText text = new FormattedText("Hello Visual Layer!",
                    new System.Globalization.CultureInfo("en-us"),
                    FlowDirection.LeftToRight,
                    new Typeface(this.FontFamily, FontStyles.Italic,
                        FontWeights.DemiBold, FontStretches.UltraExpanded),
                    TextFontSize,
                    Brushes.Green);

            // Create a DrawingVisual, and obtain the DrawingContext.
            DrawingVisual drawingVisual = new DrawingVisual();
            using (DrawingContext drawingContext = drawingVisual.RenderOpen())
            {
                // Now, call any of the methods of DrawingContext to render data.
                drawingContext.DrawRoundedRectangle(Brushes.Yellow, new Pen(Brushes.Black, 5),
                  new Rect(5, 5, 450, 100), 20, 20);
                drawingContext.DrawText(text, new Point(20, 20));
            }

            // Dynamically make a bitmap, using the data in the DrawingVisual.
            RenderTargetBitmap bmp = new RenderTargetBitmap(500, 100, 100, 90, PixelFormats.Pbgra32);
            bmp.Render(drawingVisual);

            // Set the source of the Image control!
            myImage.Source = bmp;
        }
开发者ID:usedflax,项目名称:flaxbox,代码行数:30,代码来源:MainWindow.xaml.cs

示例14: DrawBar

 private void DrawBar(DrawingContext drawingContext, int row, int column, FormattedText font)
 {
     drawingContext.DrawLine(
         new Pen(Foreground, 2),
         new Point(column * font.Width, row * font.Height),
         new Point(column * font.Width, (row + 1) * font.Height));
 }
开发者ID:faboo,项目名称:Agent,代码行数:7,代码来源:CursorPresenter.cs

示例15: OnRender

        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            double fontSize;
            Typeface typeFace;
            TextAlignment alignment;
            FlowDirection flowDirection;
            double padding;
            if (AdornedPasswordBox != null) {
                alignment = ConvertAlignment (AdornedPasswordBox.HorizontalContentAlignment);
                flowDirection = AdornedPasswordBox.FlowDirection;
                fontSize = AdornedPasswordBox.FontSize;
                typeFace = AdornedPasswordBox.FontFamily.GetTypefaces ().FirstOrDefault ();
                padding = 6;
            }
            else {
                alignment = AdornedTextBox.ReadLocalValue (TextBox.TextAlignmentProperty) !=DependencyProperty.UnsetValue ? AdornedTextBox.TextAlignment : ConvertAlignment (AdornedTextBox.HorizontalContentAlignment);
                flowDirection = AdornedTextBox.FlowDirection;
                fontSize = AdornedTextBox.FontSize;
                typeFace = AdornedTextBox.FontFamily.GetTypefaces ().FirstOrDefault ();
                padding = 6;
            }
            var text = new System.Windows.Media.FormattedText (PlaceholderText ?? "", CultureInfo.CurrentCulture, flowDirection, typeFace, fontSize, System.Windows.Media.Brushes.LightGray) {
                TextAlignment = alignment
            };

            drawingContext.DrawText (text, new System.Windows.Point (padding, (RenderSize.Height - text.Height) / 2));
        }
开发者ID:nite2006,项目名称:xwt,代码行数:27,代码来源:PlaceholderTextAdorner.cs


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