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


C# FontFamily.Dispose方法代码示例

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


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

示例1: CreateInfomationBitmap

        private static Bitmap CreateInfomationBitmap(string content, int width, int height,
			StringAlignment hAlign = StringAlignment.Near,
			StringAlignment vAlign = StringAlignment.Near)
        {
            Bitmap b = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(b);
            GraphicsPath path = new GraphicsPath();
            FontFamily fontFamily = new FontFamily("微软雅黑");
            StringFormat format = new StringFormat();
            format.Alignment = hAlign;
            format.LineAlignment = vAlign;
            path.AddString(content,
                fontFamily, (int)FontStyle.Bold, 16, new Rectangle(0, 0, width, height), format);
            fontFamily.Dispose();
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.FillPath(Brushes.Black, path);
            Pen pen = new Pen(Color.Black, 2);
            g.DrawPath(pen, path);
            g.Dispose();
            pen.Dispose();
            Bitmap infoBitmap = RenderUtils.BoxBlur(b, 1);
            g = Graphics.FromImage(infoBitmap);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.FillPath(Brushes.White, path);
            g.Dispose();
            return infoBitmap;
        }
开发者ID:KotonoYuuri,项目名称:OriginalFireBarrager,代码行数:27,代码来源:Infomations.cs

示例2: DrawRandBgString

        /// <summary>
        /// 画背景干扰文字
        /// </summary>
        /// <returns></returns>
        private Bitmap DrawRandBgString()
        {
            Bitmap b = new Bitmap(bgWidth, bgHeight);
            String[] randStr =
            {
                "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
                "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
                "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
            };
            b.MakeTransparent();
            Graphics g = Graphics.FromImage(b);

            g.Clear(Color.Transparent);
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.TextRenderingHint = TextRenderingHint.AntiAlias;
            g.InterpolationMode = InterpolationMode.HighQualityBilinear;

            //设置字体显示格式
            StringFormat format = new StringFormat(StringFormatFlags.NoClip);
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;

            FontFamily f = new FontFamily(GenericFontFamilies.Serif);
            Font textFont = new Font(f, randomStringFontSize, FontStyle.Underline);

            int randAngle = 60; //随机转动角度

            for (int i = 0; i < RandomStringCount; i++)
            {
                Brush brush = new System.Drawing.SolidBrush(GetRandomLightColor());
                Point pot = new Point(random.Next(5, bgWidth - 5), random.Next(5, bgHeight - 5));
                //随机转动的度数
                float angle = random.Next(-randAngle, randAngle);

                //转动画布
                g.RotateTransform(angle);
                g.DrawString(randStr[random.Next(randStr.Length)], textFont, brush, pot, format);
                //转回去,为下一个字符做准备
                g.RotateTransform(-angle);
                //释放资源
                brush.Dispose();
            }
            textFont.Dispose();
            format.Dispose();
            f.Dispose();

            return b;
        }
开发者ID:yonglehou,项目名称:ToolRepository,代码行数:53,代码来源:DrawValidationCode.cs

示例3: rtxShow_SelectionChanged

        private void rtxShow_SelectionChanged(object sender, EventArgs e)
        {
            try
            {
                #region Aglin
                if (rtxShow.SelectionAlignment == ExtendedRichTextBox.RichTextAlign.Left)
                {
                    btnAlignLeft.Checked = true;
                    btnAlignCenter.Checked = false;
                    btnAlignRight.Checked = false;
                }
                else if (rtxShow.SelectionAlignment == ExtendedRichTextBox.RichTextAlign.Center)
                {
                    btnAlignLeft.Checked = false;
                    btnAlignCenter.Checked = true;
                    btnAlignRight.Checked = false;
                }
                else if (rtxShow.SelectionAlignment == ExtendedRichTextBox.RichTextAlign.Right)
                {
                    btnAlignLeft.Checked = false;
                    btnAlignCenter.Checked = false;
                    btnAlignRight.Checked = true;
                }
                else
                {
                    btnAlignLeft.Checked = true;
                    btnAlignCenter.Checked = false;
                    btnAlignRight.Checked = false;
                }
                #endregion

                #region Font
                FontFamily ff = new FontFamily("Tahoma");
                if (ff.IsStyleAvailable(FontStyle.Bold) == true)
                {
                    btnBold.Enabled = true;
                    btnBold.Checked = rtxShow.SelectionCharStyle.Bold;
                }
                else
                {
                    btnBold.Enabled = false;
                    btnBold.Checked = false;
                }

                if (ff.IsStyleAvailable(FontStyle.Italic) == true)
                {
                    btnItalic.Enabled = true;
                    btnItalic.Checked = rtxShow.SelectionCharStyle.Italic;
                }
                else
                {
                    btnItalic.Enabled = false;
                    btnItalic.Checked = false;
                }

                if (ff.IsStyleAvailable(FontStyle.Underline) == true)
                {
                    btnUnderline.Enabled = true;
                    btnUnderline.Checked = rtxShow.SelectionCharStyle.Underline;
                }
                else
                {
                    btnUnderline.Enabled = false;
                    btnUnderline.Checked = false;
                }

                ff.Dispose();
                #endregion

                rtxShow.UpdateObjects();
            }
            catch (Exception)
            { }
        }
开发者ID:minhnguyen31093,项目名称:Reminiscent,代码行数:74,代码来源:UC_Dictionary.cs

示例4: DrawFontItem

        private void DrawFontItem(DrawItemEventArgs e)
        {
            FontStyle[] styles = new FontStyle[4] { FontStyle.Regular, FontStyle.Bold, FontStyle.Italic, FontStyle.Bold | FontStyle.Italic };
            if (!BarFunctions.IsOffice2007Style(m_Style))
                e.DrawBackground();
            string fontname = this.Items[e.Index].ToString();
            FontFamily family = new FontFamily(fontname);

            int iWidth = this.DropDownWidth / 2 - 4;
            if (iWidth <= 0)
                iWidth = this.Width;
            foreach (FontStyle style in styles)
            {
                if (family.IsStyleAvailable(style))
                {
                    eTextFormat format = eTextFormat.Default | eTextFormat.NoPrefix;
                    Color textColor = (e.State & DrawItemState.Selected) != 0 ? SystemColors.HighlightText : SystemColors.ControlText;

                    Office2007ButtonItemStateColorTable ct = null;
                    if (BarFunctions.IsOffice2007Style(m_Style))
                    {
                        Office2007ButtonItemColorTable bct = ((Office2007Renderer)GlobalManager.Renderer).ColorTable.ButtonItemColors[0];
                        if ((e.State & DrawItemState.Selected) != 0 || (e.State & DrawItemState.HotLight) != 0)
                            ct = bct.MouseOver;
                        else if ((e.State & DrawItemState.Disabled) != 0 || !this.Enabled)
                            ct = bct.Disabled;
                        else
                            ct = bct.Default;
                        //if (ct == null)
                        if (!this.Enabled)
                            textColor = _DisabledForeColor.IsEmpty ? SystemColors.ControlDark : _DisabledForeColor;
                        else
                            textColor = SystemColors.ControlText;

                        if ((e.State & DrawItemState.Selected) != 0 || (e.State & DrawItemState.HotLight) != 0)
                            Office2007ButtonItemPainter.PaintBackground(e.Graphics, ct, e.Bounds, RoundRectangleShapeDescriptor.RoundCorner2);
                        else
                        {
                            e.DrawBackground();
                        }
                    }

                    if ((e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit)
                    {
                        Rectangle rt = e.Bounds;
                        rt.Height = 0; // Prevents clipping based on height
                        format |= eTextFormat.NoClipping | eTextFormat.NoPadding;
                        TextDrawing.DrawString(e.Graphics, fontname, this.Font, textColor, rt, format);
                    }
                    else
                    {
                        Size szFont = TextDrawing.MeasureString(e.Graphics, fontname, this.Font);
                        int iDiff = (int)((e.Bounds.Height - szFont.Height) / 2);
                        Rectangle rFontName = new Rectangle(e.Bounds.X, e.Bounds.Y + iDiff,
                            ((e.State & DrawItemState.Disabled) == DrawItemState.Disabled ? e.Bounds.Width : Math.Max(e.Bounds.Width - 100, 32)), e.Bounds.Height - iDiff);
                        TextDrawing.DrawString(e.Graphics, fontname, this.Font, textColor, rFontName, format);
                        Rectangle rRemainder = new Rectangle(e.Bounds.X + iWidth + 4, e.Bounds.Y, e.Bounds.Width + 100, e.Bounds.Height);
                        //using(Font f = new Font(family, (float)e.Bounds.Height - 8, style))
                        using (Font f = new Font(family, this.Font.Size, style))
                            TextDrawing.DrawString(e.Graphics, fontname, f, textColor, rRemainder, format);
                    }
                    break;
                }
            }
            if (family != null) family.Dispose();
        }
开发者ID:huamanhtuyen,项目名称:VNACCS,代码行数:66,代码来源:ComboBoxEx.cs

示例5: AddString4

        private void AddString4(Graphics g)
        {
            g.Clear (Color.FromArgb(255,204,204,204));

            var myPath = new GraphicsPath ();

            FontFamily fntFamily = new FontFamily("Times New Roman");
            string s="Embossed Text";

            myPath.AddString (s, fntFamily, 0, 50, new PointF (28, 28), StringFormat.GenericTypographic);
            g.FillPath (Brushes.White, myPath);

            myPath.Reset ();
            myPath.AddString (s, fntFamily, 0, 50, new PointF (32, 32), StringFormat.GenericTypographic);
            g.FillPath (Brushes.DarkGray, myPath);

            myPath.Reset ();
            myPath.AddString (s, fntFamily, 0, 50, new PointF (30, 30), StringFormat.GenericTypographic);
            g.FillPath (Brushes.Black, myPath);

            s="Chiseled Text";
            myPath.Reset ();
            myPath.AddString (s, fntFamily, 0, 50, new PointF (28, 108), StringFormat.GenericTypographic);
            g.FillPath (Brushes.DarkGray, myPath);

            myPath.Reset ();
            myPath.AddString (s, fntFamily, 0, 50, new PointF (32, 112), StringFormat.GenericTypographic);
            g.FillPath (Brushes.LightGray, myPath);

            myPath.Reset ();
            myPath.AddString (s, new FontFamily ("Times New Roman"), 0, 50, new PointF (30, 110), StringFormat.GenericTypographic);
            g.FillPath (Brushes.SeaShell, myPath);

            fntFamily.Dispose();
        }
开发者ID:mono,项目名称:sysdrawing-coregraphics,代码行数:35,代码来源:DrawingView.cs

示例6: Render


//.........这里部分代码省略.........
                    if (fontName.EndsWith("MT")) fontName = fontName.Substring(0, fontName.Length - 2);
                    //Remove -Bold, -Italic, -BoldItalic
                    if (fontName.EndsWith("-Bold", StringComparison.OrdinalIgnoreCase)) style |= FontStyle.Bold;
                    if (fontName.EndsWith("-Italic", StringComparison.OrdinalIgnoreCase)) style |= FontStyle.Italic;
                    if (fontName.EndsWith("-BoldItalic", StringComparison.OrdinalIgnoreCase)) style |= FontStyle.Bold | FontStyle.Italic;
                    //Remove from fontName
                    fontName = new Regex("\\-(Bold|Italic|BoldItalic)$", RegexOptions.IgnoreCase | RegexOptions.IgnoreCase).Replace(fontName, "");
                    //Remove PS
                    if (fontName.EndsWith("PS")) fontName = fontName.Substring(0, fontName.Length - 2);
                    //Find font family
                    try {
                        fontFamily = new FontFamily(fontName);
                    } catch (ArgumentException ae) {
                        if (IgnoreMissingFonts) {
                            fontFamily = FontFamily.GenericSansSerif;
                        } else throw ae;

                    }
                    if (fauxBold) style |= FontStyle.Bold;
                    if (fauxItalic) style |= FontStyle.Italic;
                    if (underline) style |= FontStyle.Underline;
                    if (strikethrough) style |= FontStyle.Strikeout;

                    strformat = new StringFormat();
                    strformat.LineAlignment = hAlign;
                    strformat.Alignment = vAlign;
                    strformat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.NoClip;
                    if (!horizontal) strformat.FormatFlags |= StringFormatFlags.DirectionVertical;
                    strformat.Trimming = StringTrimming.None;

                    path.AddString(text, fontFamily,
                        (int)style, (float)(fontSize),rect, strformat);
                }finally{
                    fontFamily.Dispose();
                    strformat.Dispose();
                }

                if (glowFlag)
                {
                    if (glowWidth == 3) glowWidth = 2; //To replicate photoshop rounding bug

                    double finalOpacity = (glowOpacity + 1.5)/2.5; //Because Photoshop doesn't actually use the opacity as the final opacity...
                    //Add a 30% fade inside the glow width
                    int fadeWidth = (int)Math.Floor(glowWidth * 0.33);

                    double totalOpacity = 0; //Start at transparent

                    //start with outermost ring, work inwards
                    for (int i = fadeWidth; i >=0; i--)
                    {
                        //How much opacity do we lack to complete the desired opacity?
                        //totalOpacity = prevOpacity * (1-curOpacity) + curOpacity
                        //a=b *(1-c) + c
                        //>>> where b!=1, c=(b-a/b-1)
                        double missingOpacity = (totalOpacity - finalOpacity) / (totalOpacity - 1);

                        int remainingRings = fadeWidth;

                        double currentOpacity = missingOpacity / (fadeWidth + 1);
                        //Update total opacity
                        totalOpacity = totalOpacity * (1 - currentOpacity) + currentOpacity;
                        //Draw it
                        using (Pen pen = new Pen(Color.FromArgb((int)Math.Round(currentOpacity * 255.0), glowColor), (float)((glowWidth - fadeWidth + (double)i) * 2)))
                        {
                            pen.LineJoin = LineJoin.Round;
                            g.DrawPath(pen, path);
开发者ID:stukalin,项目名称:ImageResizer,代码行数:67,代码来源:TextLayerRenderer.cs

示例7: GetFont

        public static Font GetFont(String familyName, float size, FontStyle style)
        {
            Font result = null;
              FontFamily family = null;
              try
              {
            family = new FontFamily(familyName);
            if (family.IsStyleAvailable(style))
              result = new Font(familyName, size, style);
            else
            {
              // On some systems even the regular style throws an exception (which actually should not happen
              // as Windows should automatically pick an alternative font if the one requested does not exist, but
              // there are cases...).
              result = new Font(familyName, size, FontStyle.Regular);
            }
              }
              catch
              {
            result = new Font(FontFamily.GenericSansSerif, size, style);
              }

              if (family != null)
            family.Dispose();
              return result;
        }
开发者ID:abibell,项目名称:mysql-workbench,代码行数:26,代码来源:ControlUtilities.cs

示例8: txtTaskDes_SelectionChanged

        private void txtTaskDes_SelectionChanged(object sender, EventArgs e)
        {
            try
            {
                #region Aglin
                if (txtTaskDes.SelectionAlignment == ExtendedRichTextBox.RichTextAlign.Left)
                {
                    btnLeft2.Checked = true;
                    btnCenter2.Checked = false;
                    btnRight2.Checked = false;
                }
                else if (txtTaskDes.SelectionAlignment == ExtendedRichTextBox.RichTextAlign.Center)
                {
                    btnLeft2.Checked = false;
                    btnCenter2.Checked = true;
                    btnRight2.Checked = false;
                }
                else if (txtTaskDes.SelectionAlignment == ExtendedRichTextBox.RichTextAlign.Right)
                {
                    btnLeft2.Checked = false;
                    btnCenter2.Checked = false;
                    btnRight2.Checked = true;
                }
                else
                {
                    btnLeft2.Checked = true;
                    btnCenter2.Checked = false;
                    btnRight2.Checked = false;
                }
                #endregion

                #region Font
                FontFamily ff = new FontFamily("Tahoma");
                if (ff.IsStyleAvailable(FontStyle.Bold) == true)
                {
                    btnB2.Enabled = true;
                    btnB2.Checked = txtTaskDes.SelectionCharStyle.Bold;
                }
                else
                {
                    btnB2.Enabled = false;
                    btnB2.Checked = false;
                }

                if (ff.IsStyleAvailable(FontStyle.Italic) == true)
                {
                    btnI2.Enabled = true;
                    btnI2.Checked = txtTaskDes.SelectionCharStyle.Italic;
                }
                else
                {
                    btnI2.Enabled = false;
                    btnI2.Checked = false;
                }

                if (ff.IsStyleAvailable(FontStyle.Underline) == true)
                {
                    btnU2.Enabled = true;
                    btnU2.Checked = txtTaskDes.SelectionCharStyle.Underline;
                }
                else
                {
                    btnU2.Enabled = false;
                    btnU2.Checked = false;
                }

                ff.Dispose();
                #endregion

                //txtTaskDes.UpdateObjects();
            }
            catch (Exception)
            { }
        }
开发者ID:minhnguyen31093,项目名称:Reminiscent,代码行数:74,代码来源:NewSchedule.cs

示例9: PaintValue

        public override void PaintValue(PaintValueEventArgs e)
        {
            string name = e.Value as string;
            switch (name)
            {
                case null:
                    break;

                case "":
                    return;

                default:
                {
                    e.Graphics.FillRectangle(SystemBrushes.ActiveCaption, e.Bounds);
                    FontFamily fontFamily = null;
                    try
                    {
                        fontFamily = new FontFamily(name);
                    }
                    catch
                    {
                    }
                    if (fontFamily != null)
                    {
                        try
                        {
                            DrawFontSample(e, fontFamily, FontStyle.Regular);
                        }
                        catch
                        {
                            try
                            {
                                DrawFontSample(e, fontFamily, FontStyle.Italic);
                            }
                            catch
                            {
                                try
                                {
                                    DrawFontSample(e, fontFamily, FontStyle.Bold);
                                }
                                catch
                                {
                                    try
                                    {
                                        DrawFontSample(e, fontFamily, FontStyle.Italic | FontStyle.Bold);
                                    }
                                    catch
                                    {
                                    }
                                }
                            }
                        }
                        finally
                        {
                            fontFamily.Dispose();
                        }
                    }
                    e.Graphics.DrawLine(SystemPens.WindowFrame, e.Bounds.Right, e.Bounds.Y, e.Bounds.Right, e.Bounds.Bottom);
                    break;
                }
            }
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:62,代码来源:FontNameEditor.cs

示例10: FontExists

 public static bool FontExists(string fontname)
 {
     #if false
     // Get the glyphTypeface to see if the font exists.
     GlyphTypeface glyphTypeface;
     Typeface typeface = new Typeface(fontname);
     return typeface.TryGetGlyphTypeface(out glyphTypeface);
     #else
     // Doesn't seem to be an easy way to determine if a font exists.
     try {
         FontFamily family = new FontFamily(fontname);
         family.Dispose();
         return true;
     }
     catch {
         return false;
     }
     #endif
 }
开发者ID:jonc,项目名称:carto,代码行数:19,代码来源:Util.cs


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