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


C# FormattedText.SetFontWeight方法代码示例

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


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

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

示例2: MeasureTextWidth

 public static double MeasureTextWidth(string text, double fontSize, string fontFamily, FontWeight fontWeight)
 {
     var formattedText = new FormattedText(
         text,
         System.Globalization.CultureInfo.InvariantCulture,
         FlowDirection.LeftToRight,
         new Typeface(fontFamily.ToString()),
         fontSize,
         Brushes.Black
     );
     formattedText.SetFontWeight(fontWeight);
     return formattedText.WidthIncludingTrailingWhitespace;
 }
开发者ID:bajdcc,项目名称:NewsApp,代码行数:13,代码来源:UIHelper.cs

示例3: DrawBoldText

        public static void DrawBoldText(DrawingContext drawingContext, string str, Point pt)
        {
            FormattedText newText = new FormattedText(str,
                Configurations.culture,
                FlowDirection.LeftToRight,
                Configurations.TypeFace,
                Configurations.TextSize,
                Configurations.TextBoldColor);

            newText.SetFontWeight(FontWeights.SemiBold);
            Geometry textGeometry = newText.BuildGeometry(pt);
            drawingContext.DrawGeometry(Configurations.TextBoldColor, null, textGeometry);
            //drawingContext.DrawText(newText, pt);
        }
开发者ID:samuto,项目名称:designscript,代码行数:14,代码来源:Utilities.cs

示例4: GetFormattedText

        public static FormattedText GetFormattedText(this FlowDocument doc)
        {
            if (doc == null)
            {
                throw new ArgumentNullException("doc");
            }

            FormattedText output = new FormattedText(
              GetText(doc),
              CultureInfo.CurrentCulture,
              doc.FlowDirection,
              new Typeface(doc.FontFamily, doc.FontStyle, doc.FontWeight, doc.FontStretch),
              doc.FontSize,
              doc.Foreground);

            int offset = 0;

            foreach (TextElement el in GetRunsAndParagraphs(doc))
            {
                Run run = el as Run;

                if (run != null)
                {
                    int count = run.Text.Length;

                    output.SetFontFamily(run.FontFamily, offset, count);
                    output.SetFontStyle(run.FontStyle, offset, count);
                    output.SetFontWeight(run.FontWeight, offset, count);
                    output.SetFontSize(run.FontSize, offset, count);
                    output.SetForegroundBrush(run.Foreground, offset, count);
                    output.SetFontStretch(run.FontStretch, offset, count);
                    output.SetTextDecorations(run.TextDecorations, offset, count);

                    offset += count;
                }
                else
                {
                    offset += Environment.NewLine.Length;
                }
            }

            return output;
        }
开发者ID:RagingBigFemaleBird,项目名称:sgs,代码行数:43,代码来源:FlowDocumentExtensions.cs

示例5: OnRender

        protected override void OnRender(DrawingContext drawingContext)
        {
            //drawingContext.DrawRectangle(Brushes.Crimson, null, new Rect(new Point(0, 0), new Point(500, 500)));
            //base.OnRender(drawingContext);

            //return;

            string testString = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor";

            // Create the initial formatted text string.
            FormattedText formattedText = new FormattedText(
                testString,
                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.
            formattedText.MaxTextWidth = 300;
            formattedText.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.
            formattedText.SetFontSize(36 * (96.0 / 72.0), 0, 5);

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

            // Use a linear gradient brush beginning at the 6th character and continuing for 11 characters.
            formattedText.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.
            formattedText.SetFontStyle(FontStyles.Italic, 28, 28);

            // Draw the formatted text string to the DrawingContext of the control.
            drawingContext.DrawText(formattedText, new Point(10, 0));
        }
开发者ID:aistrate,项目名称:Throwaways,代码行数:43,代码来源:Window1.xaml.cs

示例6: DrawSteps

        private void DrawSteps(DrawingContext drawingContext, Pen pen)
        {
            for (decimal i = Start; i < Stop; i += Step)
            {
                double x = ((double)((i - Start) / (Stop - Start)) * ActualWidth);

                drawingContext.DrawLine(pen, new Point(x, ActualHeight), new Point(x, ActualHeight * 0.6));

                FormattedText value = new FormattedText(i.ToString(CultureInfo.CurrentCulture),
                            CultureInfo.CurrentCulture,
                            FlowDirection.LeftToRight,
                            new Typeface("Arial"),
                            PtToDip((int)(ActualHeight / 3)),
                            Brush);
                value.SetFontWeight(FontWeights.Regular);
                value.TextAlignment = TextAlignment.Center;

                drawingContext.DrawText(value, new Point(x, ActualHeight * 0.1));
            }
        }
开发者ID:domin1991,项目名称:dwachWPF,代码行数:20,代码来源:Ruler.cs

示例7: CreateDrawingVisualText

        // Create a DrawingVisual that contains text.
        private DrawingVisual CreateDrawingVisualText(double x, double y, string vals, bool isBold, bool rotate90, TextAlignment align, int fontSize)
        {
            // Create an instance of a DrawingVisual.
            DrawingVisual drawingVisual = new DrawingVisual();
            // Retrieve the DrawingContext from the DrawingVisual.
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            FormattedText ft = new FormattedText(vals,
                  CultureInfo.GetCultureInfo("en-us"),
                  FlowDirection.LeftToRight,
                  new Typeface("Verdana"),
                  fontSize, Brushes.LightGray);
            ft.SetFontWeight(FontWeights.Bold);
            ft.TextAlignment = align;
            // Draw a formatted text string into the DrawingContext.
            drawingContext.DrawText(ft, new Point(x, y));

            // Close the DrawingContext to persist changes to the DrawingVisual.
            drawingContext.Close();

            return drawingVisual;
        }
开发者ID:dioptre,项目名称:nkd,代码行数:23,代码来源:2DRenderHelper.cs

示例8: Drawing

        public new void Drawing()
        {
            using (DrawingContext dc = this.RenderOpen())
            {
                FormattedText formattedText = new FormattedText(
                    Text,
                    CultureInfo.GetCultureInfo("zh-Hans"),
                    FlowDirection.LeftToRight,
                    new Typeface("微软雅黑"),
                    FontSize,
                    DrawBrush);

                formattedText.SetFontWeight(FontWeights.ExtraBold);

                double X = Position.X;
                if (X > (formattedText.Width / 2)) X -= (formattedText.Width / 2);
                double Y = Position.Y;
                if (Y > (formattedText.Height / 2)) Y -= (formattedText.Height / 2);

                dc.DrawText(formattedText, new Point(X, Y));
            }
        }
开发者ID:baidang201,项目名称:ProductExcel,代码行数:22,代码来源:TextVisual.cs

示例9: GetUsernameWidth

 /// <summary>
 /// The get username width.
 /// </summary>
 /// <returns>
 /// The <see cref="double"/>.
 /// </returns>
 private double GetUsernameWidth()
 {
     var f = new FormattedText(
         this.User.UserName,
         CultureInfo.CurrentCulture,
         FlowDirection.LeftToRight,
         new Typeface("Arial"),
         12,
         Brushes.Black);
     f.SetFontWeight(FontWeights.Bold);
     return f.Width + 10;
 }
开发者ID:jonbonne,项目名称:OCTGN,代码行数:18,代码来源:ChatTableRow.xaml.cs

示例10: RenderStats

        protected void RenderStats(DrawingContext dc)
        {
            string text =
                "Position: " + hexGrid.ToWorldPoint(Mouse.GetPosition(this)).Round(1).ToString() + Environment.NewLine +
                "Ms For Frame: " + fpsStats + Environment.NewLine;

            FormattedText fText = new FormattedText(text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), 14, Brushes.Lime);

            fText.SetFontWeight(FontWeights.DemiBold);
            dc.DrawText(fText, new Point());
        }
开发者ID:Rupini,项目名称:HexEditor,代码行数:11,代码来源:MainBlackBoard.cs

示例11: ApplyFormat

 /// <summary>
 /// Applies a format in rule options to the formatted text
 /// </summary>
 /// <param name="text"></param>
 /// <param name="options"></param>
 /// <param name="index"></param>
 /// <param name="length"></param>
 public void ApplyFormat(FormattedText text, RuleOptions options, int index, int length)
 {
     text.SetForegroundBrush(options.Foreground, index, length);
     text.SetFontWeight(options.FontWeight, index, length);
     text.SetFontStyle(options.FontStyle, index, length);
 }
开发者ID:diegoRodriguezAguila,项目名称:SGAM.Elfec.Admin,代码行数:13,代码来源:BaseHighlighter.cs

示例12: ApplyPrintStyles

        static void ApplyPrintStyles(FormattedText formattedText,ExportText exportText)
        {
            var font = exportText.Font;
            var textDecorations = new TextDecorationCollection();
            FontStyle fontStyle;
            FontWeight fontWeight;

            if ((font.Style & System.Drawing.FontStyle.Italic) != 0) {
                fontStyle = FontStyles.Italic;
            } else {
                fontStyle = FontStyles.Normal;
            }

            formattedText.SetFontStyle(fontStyle);

            if ((font.Style & System.Drawing.FontStyle.Bold) != 0) {
                fontWeight = FontWeights.Bold;
            } else {
                fontWeight = FontWeights.Normal;
            }
            formattedText.SetFontWeight(fontWeight);

            if ((font.Style & System.Drawing.FontStyle.Underline) != 0) {
                textDecorations.Add(TextDecorations.Underline);
            }

            if ((font.Style & System.Drawing.FontStyle.Strikeout) != 0) {
                textDecorations.Add(TextDecorations.Strikethrough);
            }

            formattedText.SetTextDecorations(textDecorations);
        }
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:32,代码来源:FixedDocumentCreator.cs

示例13: OnRender

        // OnRender�� �������̵�
        protected override void OnRender(DrawingContext dc)
        {
            Size size = RenderSize;

            // ���� ��� RenderSize ����
            if (Stroke != null)
            {
                //Thickness������Ƽ ��ŭ Ÿ���� ������ ���δ�.
                size.Width = Math.Max(0, size.Width - Stroke.Thickness);
                size.Height = Math.Max(0, size.Height - Stroke.Thickness);
            }

            // Ÿ�� �׸���
            dc.DrawEllipse(Fill, Stroke,
                new Point(RenderSize.Width / 2, RenderSize.Height / 2),
                size.Width / 2, size.Height / 2);

            #region �߰����� �ڵ�
            string testString = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor";

            // FormattedText ����
            FormattedText formtxt = new FormattedText(
                testString, //���ڿ�
                CultureInfo.GetCultureInfo("en-us"),//Text Ư�� ��ȭ��
                FlowDirection.LeftToRight,          //Text �д� ����
                new Typeface("Verdana"),            //Text ��Ÿ��
                32,                                 //�۲� ũ��
                Brushes.Black);                     //�귯�� ����

            // Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears.
            formtxt.MaxTextWidth = 300;             //Text ���� �ִ���
            formtxt.MaxTextHeight = 240;            //Text ���� �ִ����

            // 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.
            formtxt.SetFontSize(36 * (96.0 / 72.0), 0, 5);

            // ������ �ؽ�Ʈ �� ���� (����, ��ġ, ����)
            formtxt.SetFontWeight(FontWeights.Bold, 6, 11);

            // ������ �ؽ�Ʈ �׶��̼� �ֱ�
            formtxt.SetForegroundBrush(
                                    new LinearGradientBrush(
                                    Colors.Orange,
                                    Colors.Teal,
                                    90.0),                      //�귯��(�׶��̼�)
                                    6, 11);                     //��ġ, ����

            // ������ �ؽ�Ʈ�� ��Ʈ��Ÿ��
            formtxt.SetFontStyle(FontStyles.Italic, 28, 28);

            //���
            dc.DrawText(formtxt, new Point((RenderSize.Width - formtxt.Width) / 2,
                                            (RenderSize.Height - formtxt.Height) / 2));
            #endregion

            dc.PushClip(new RectangleGeometry(new Rect(new Point(0, 0), RenderSize)));
        }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:59,代码来源:BetterEllipse.cs

示例14: setStyle

        public void setStyle(CharDisplayInfo fs, FontChanges fc, FormattedText ft, DrawingContext dc)
        {
            int startPos = fc.Offset + fc.StartCol;

            if ((fs.Style & (int)ZStyles.BOLDFACE_STYLE) > 0)
            {
                ft.SetFontWeight(FontWeights.Bold, startPos, fc.Count);
            }

            int rectColor = -1;
            ColorType type = ColorType.Foreground;

            if ((fs.Style & (int)ZStyles.REVERSE_STYLE) > 0)
            {
                ft.SetFontWeight(FontWeights.Bold, startPos, fc.Count);
                ft.SetForegroundBrush(ZColorCheck.ZColorToBrush(fs.BackgroundColor, ColorType.Background), startPos, fc.Count);

                rectColor = fs.ForegroundColor;
            }
            else
            {
                ft.SetForegroundBrush(ZColorCheck.ZColorToBrush(fs.ForegroundColor, ColorType.Foreground), startPos, fc.Count);
                if (fs.BackgroundColor > 1 && fs.BackgroundColor != bColor)
                {
                    rectColor = fs.BackgroundColor;
                    type = ColorType.Background;
                }
            }

            if ((fs.Style & (int)ZStyles.EMPHASIS_STYLE) > 0)
            {
                ft.SetFontStyle(FontStyles.Italic, startPos, fc.Count);
            }

            if ((fs.Style & (int)ZStyles.FIXED_WIDTH_STYLE) > 0)
            {
                ft.SetFontFamily(_fixedFont.Family, startPos, fc.Count);
            }

            if (dc != null && rectColor != -1)
            {
                Brush b = ZColorCheck.ZColorToBrush(rectColor, type);

                dc.DrawRectangle(b, null,
                    new Rect(fc.StartCol * charWidth, fc.Line * charHeight,
                        fc.Count * charWidth, charHeight));
            }
        }
开发者ID:ChrisJamesSadler,项目名称:Cosmos,代码行数:48,代码来源:TextControlScreen.xaml.cs

示例15: MenuItemInfo

        internal MenuItemInfo(string menuText, string keyword, MenuItemAnchor anchor)
        {
            FormattedText geomItem = new FormattedText(menuText,
                     Configurations.culture,
                     FlowDirection.LeftToRight,
                     Configurations.TypeFace,
                     Configurations.MinimumTextSize,
                     this.color);

            if (this.SetKeyword(keyword, menuText))
                geomItem.SetFontWeight(FontWeights.UltraBlack, this.keywordStartIndex, keyword.Length);
            double length = geomItem.WidthIncludingTrailingWhitespace;
            this.currentPosition = new Point(0, 0);
            this.previousPosition = new Point(0, 0);
            this.anchor = anchor;
            this.ItemPosition = new Point(0, 0);
            this.ItemLength = length;
            double rectHeight = (Configurations.MinimumTextSize + Configurations.MaxHeightIncrement);

            //Each item has a trailing and leading rectangle which is painted with a linear gradient
            //from transparent to white.
            Rect background = new Rect(this.ItemPosition, new Size(this.ItemLength, rectHeight));
            Rect rectTrailing = new Rect(this.ItemPosition, new Size(Configurations.EndRectangleLength, rectHeight));
            Rect rectLeading = new Rect(this.ItemPosition, new Size(Configurations.EndRectangleLength, rectHeight));
            this.color = Configurations.NormalTextColor;

            itemGeometry.text = geomItem.BuildGeometry(this.ItemPosition);
            itemGeometry.rectangleTrailing = new RectangleGeometry(rectTrailing);
            itemGeometry.rectangleLeading = new RectangleGeometry(rectLeading);
            itemGeometry.background = new RectangleGeometry(background);

            geometry = geomItem.BuildGeometry(this.ItemPosition);
            this.ItemHeight = Configurations.MinimumTextSize;
        }
开发者ID:samuto,项目名称:designscript,代码行数:34,代码来源:RadialMenu.cs


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