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


C# FontFamily.IsStyleAvailable方法代码示例

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


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

示例1: OnDrawItem

        /// <summary>
        /// Occurs during the drawing of an item
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {

            Rectangle outer = e.Bounds;
            outer.Inflate(1, 1);
            e.Graphics.FillRectangle(Brushes.White, outer);
            Brush fontBrush = Brushes.Black;
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                Rectangle r = e.Bounds;
                r.Inflate(-1, -1);
                e.Graphics.FillRectangle(Global.HighlightBrush(r, Color.FromArgb(215, 238, 252)), r);
                Pen p = new Pen(Color.FromArgb(215, 238, 252));
                Global.DrawRoundedRectangle(e.Graphics, p, e.Bounds);
                p.Dispose();
            }
           
          
            string name = Items[e.Index].ToString();
            FontFamily ff = new FontFamily(name);
            Font fnt = new Font("Arial", 10, FontStyle.Regular);
            if (ff.IsStyleAvailable(FontStyle.Regular))
            {
                fnt = new Font(name, 10, FontStyle.Regular);
            }
            else if (ff.IsStyleAvailable(FontStyle.Italic))
            {
                fnt = new Font(name, 10, FontStyle.Italic);
            }
            SizeF box = e.Graphics.MeasureString(name, Font);
            e.Graphics.DrawString(name, Font, fontBrush, e.Bounds.X, e.Bounds.Y);
            e.Graphics.DrawString("ABC", fnt, fontBrush, e.Bounds.X + box.Width, e.Bounds.Y);

        }
开发者ID:zhongshuiyuan,项目名称:mapwindowsix,代码行数:38,代码来源:FontFamilyDropDown.cs

示例2: xxcbDrawItem

        private void xxcbDrawItem(object sender, DrawItemEventArgs e)
        {
            //drawItems here
            if (sender == null)
                return;
            if (e.Index < 0)
                return;
            //Get the Combo from the sender object
            ComboBox cbo = (ComboBox)sender;
            //Get the FontFamily from put in constructor
            FontFamily ff = new FontFamily(cbo.Items[e.Index].ToString());
            //Set font style
            FontStyle fs = FontStyle.Regular;
            if (!ff.IsStyleAvailable(fs))
                fs = FontStyle.Italic;
            if (!ff.IsStyleAvailable(fs))
                fs = FontStyle.Bold;
            //Set font for drawing with (wich is the font itself)
            Font font = new Font(ff, 8, fs);

            //draw the background and focus rectangle
            e.DrawBackground();
            e.DrawFocusRectangle();
            //get graphics
            Graphics g = e.Graphics;
            //And draw with whatever font and brush we wish
            g.DrawString(font.Name, font, Brushes.ForestGreen, e.Bounds.X, e.Bounds.Y);

        }
开发者ID:dbbotkin,项目名称:PrimeComm,代码行数:29,代码来源:FontBrowser.cs

示例3: OnDrawItem

        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (!this.Enabled)
            {
                e.Graphics.FillRectangle(SystemBrushes.Control, e.Bounds);
            }
            else
            {
                e.DrawBackground();

                string fontName = null;
                if (e.Index == -1)
                {
                    // Text shown in the combobox itself
                    fontName = this.Text;
                }
                else
                {
                    fontName = (string)this.Items[e.Index];
                }

                Font font = null;
                if ((fontName != null) && (fontName.Length != 0))
                {
                    try
                    {
                        FontFamily fontFamily = new FontFamily(fontName);
                        FontStyle fontStyle = FontStyle.Regular;
                        if (!fontFamily.IsStyleAvailable(fontStyle))
                        {
                            fontStyle = FontStyle.Italic;
                            if (!fontFamily.IsStyleAvailable(fontStyle))
                            {
                                fontStyle = FontStyle.Bold;
                                if (!fontFamily.IsStyleAvailable(fontStyle))
                                {
                                    throw new NotSupportedException();
                                }
                            }
                        }

                        font = new Font(fontName, (float)((e.Bounds.Height - 2) / 1.2), fontStyle, GraphicsUnit.Pixel);
                    }
                    catch (Exception)
                    {
                    }
                }

                Rectangle textBounds = new Rectangle(e.Bounds.Left + 2, e.Bounds.Top, e.Bounds.Width - 2, e.Bounds.Height);
                using (TextGraphics textGraphics = new TextGraphics(e.Graphics))
                {
                    textGraphics.DrawText(fontName, textBounds.Location, (font != null) ? font : e.Font, e.ForeColor);
                }

                if (font != null)
                {
                    font.Dispose();
                }
            }
        }
开发者ID:NickCorn,项目名称:Writer,代码行数:60,代码来源:FontComboBox.cs

示例4: GetFont

		private Font GetFont(FontFamily family, FontStyle style, float size)
		{
			if (family.IsStyleAvailable(style))
			{
				return new Font(family, size, style);
			}
			var styleWithDefault = style |= GetDefaultStyle(family);
			if (family.IsStyleAvailable(styleWithDefault))
			{
				return new Font(family, size, style);
			}

			return new Font(family, size, SelectionFont.Style);
		}
开发者ID:TargetProcess,项目名称:Tp.TrayUtility,代码行数:14,代码来源:TpRichText.cs

示例5: GetDefaultStyle

		public static FontStyle GetDefaultStyle(FontFamily fontFamily)
		{
			if (fontFamily.IsStyleAvailable(FontStyle.Regular))
				return FontStyle.Regular;
			if (fontFamily.IsStyleAvailable(FontStyle.Bold))
				return FontStyle.Bold;
			if (fontFamily.IsStyleAvailable(FontStyle.Italic))
				return FontStyle.Italic;
			if (fontFamily.IsStyleAvailable(FontStyle.Underline))
				return FontStyle.Underline;
			if (fontFamily.IsStyleAvailable(FontStyle.Strikeout))
				return FontStyle.Strikeout;
			return FontStyle.Regular;
		}
开发者ID:TargetProcess,项目名称:Tp.TrayUtility,代码行数:14,代码来源:TpRichText.cs

示例6: GetFittingStyle

        public static FontStyle GetFittingStyle(FontFamily ff)
        {
            var style = FontStyle.Regular;

            if (!ff.IsStyleAvailable(style))
            {
                style = ff.IsStyleAvailable(FontStyle.Bold)
                            ? FontStyle.Bold
                            : ff.IsStyleAvailable(FontStyle.Italic)
                                  ? FontStyle.Italic
                                  : ff.IsStyleAvailable(FontStyle.Strikeout)
                                        ? FontStyle.Strikeout
                                        : FontStyle.Underline;
            }

            return style;
        }
开发者ID:davidconde,项目名称:FontBuilder,代码行数:17,代码来源:Helper.cs

示例7: FontFromUiDialogFont

        ///<summary>
        /// Convert a UI Dialog Font to a System.Drawing.Font
        /// </summary>
        public static Font FontFromUiDialogFont(UIDLGLOGFONT logFont) {
            var conversion = new char[logFont.lfFaceName.Length];
            for(int i = 0; i < logFont.lfFaceName.Length; i++) {
                conversion[i] = (char)logFont.lfFaceName[i];
            }

            var familyName = new String(conversion);
            var emSize = Math.Abs(logFont.lfHeight);
            var style = FontStyle.Regular;
            int FW_NORMAL = 400;

            if (logFont.lfItalic > 0) {
                style |= FontStyle.Italic;
            }
            if (logFont.lfUnderline > 0) {
                style |= FontStyle.Underline;
            }
            if (logFont.lfStrikeOut > 0) {
                style |= FontStyle.Strikeout;
            }
            if (logFont.lfWeight > FW_NORMAL) {
                style |= FontStyle.Bold;
            }

            var unit = GraphicsUnit.Pixel;
            var gdiCharSet = logFont.lfCharSet;
            var ff = new FontFamily(familyName);

            var teststyles = new FontStyle[5];
            teststyles[0] = style;
            teststyles[1] = FontStyle.Regular;
            teststyles[2] = FontStyle.Bold;
            teststyles[3] = FontStyle.Italic;
            teststyles[4] = FontStyle.Bold | FontStyle.Italic;

            for (int i = 0; i < teststyles.Length; i++) {
                if (ff.IsStyleAvailable(teststyles[i])) {
                    style = teststyles[i];
                    return new Font(familyName, emSize, style, unit, gdiCharSet);
                }
            }

            // We can't find a valid style for this font - fallback to just size and unit
            return new Font(familyName, emSize, unit);
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:48,代码来源:IdeUtilities.cs

示例8: cbDrawItem

        private void cbDrawItem(object sender, DrawItemEventArgs e)
        {
            Font font1;
            Rectangle rectangle1 = e.Bounds;
            int num1 = rectangle1.X;
            rectangle1 = e.Bounds;
            int num2 = rectangle1.Y;

            if (e.Index < 0)
            {
                e.DrawBackground();
                e.DrawFocusRectangle();
                return;
            }

            e.DrawBackground();
            e.DrawFocusRectangle();


            Brush colorbrush = SystemBrushes.ControlText;


            if ((e.State & System.Windows.Forms.DrawItemState.Selected) == System.Windows.Forms.DrawItemState.Selected)
                colorbrush = SystemBrushes.HighlightText;


            if (this.m_ShowName)
            {
                e.Graphics.DrawString(this.cb.Items[e.Index].ToString(), base.Font, colorbrush, ((float)num1), ((float)num2));
                num1 += 160;

            }
            if (!this.m_ShowSample)
            {
                return;

            }
            FontFamily family1 = new FontFamily(this.cb.Items[e.Index].ToString());
            if (family1.IsStyleAvailable(FontStyle.Regular))
            {
                font1 = new Font(this.cb.Items[e.Index].ToString(), 10f, FontStyle.Regular);

            }
            else
            {
                if (family1.IsStyleAvailable(FontStyle.Bold))
                {
                    font1 = new Font(this.cb.Items[e.Index].ToString(), 10f, FontStyle.Bold);
                }
                else if (family1.IsStyleAvailable(FontStyle.Italic))
                {
                    font1 = new Font(this.cb.Items[e.Index].ToString(), 10f, FontStyle.Italic);
                }
                else
                    font1 = new Font(this.cb.Items[e.Index].ToString(), 10f, (FontStyle.Italic | FontStyle.Bold));
            }

            e.Graphics.DrawString(this.cb.Items[e.Index].ToString(), font1, colorbrush, ((float)num1), ((float)num2));
            font1.Dispose();

        }
开发者ID:dbbotkin,项目名称:PrimeComm,代码行数:61,代码来源:FontBrowser.cs

示例9: ConfigureFontStyleControl

 private void ConfigureFontStyleControl(FontFamily zFamily, FontStyle eStyle, CheckBox checkBox)
 {
     checkBox.Enabled = zFamily.IsStyleAvailable(eStyle);
     if (!checkBox.Enabled)
     {
         checkBox.Checked = false;
     }
 }
开发者ID:ksuquix,项目名称:cardmaker,代码行数:8,代码来源:MDIElementControl.cs

示例10: lbDrawItem

        private void lbDrawItem(object sender, DrawItemEventArgs e)
        {
            Brush brush1;
            Brush brush2;
            Font font1;
            Rectangle rectangle1 = e.Bounds;
            int num1 = rectangle1.X;
            rectangle1 = e.Bounds;
            int num2 = rectangle1.Y;
            if (this.lb.SelectedIndex == e.Index)
            {
                brush1 = SystemBrushes.ActiveCaption;
                brush2 = SystemBrushes.HighlightText;

            }
            else
            {
                brush1 = SystemBrushes.Window;
                brush2 = SystemBrushes.ControlText;

            }
            e.Graphics.FillRectangle(brush1, e.Bounds);
            if (this.m_ShowName)
            {
                e.Graphics.DrawString(this.lb.Items[e.Index].ToString(), base.Font, brush2, ((float)num1), ((float)num2));
                num1 += 160;

            }
            if (!this.m_ShowSample)
            {
                return;

            }
            FontFamily family1 = new FontFamily(this.lb.Items[e.Index].ToString());
            if (family1.IsStyleAvailable(FontStyle.Regular))
            {
                font1 = new Font(this.lb.Items[e.Index].ToString(), 10f, FontStyle.Regular);

            }
            else
            {
                if (family1.IsStyleAvailable(FontStyle.Bold))
                {
                    font1 = new Font(this.lb.Items[e.Index].ToString(), 10f, FontStyle.Bold);
                    goto Label_0194;

                }
                if (family1.IsStyleAvailable(FontStyle.Italic))
                {
                    font1 = new Font(this.lb.Items[e.Index].ToString(), 10f, FontStyle.Italic);
                    goto Label_0194;

                }
                font1 = new Font(this.lb.Items[e.Index].ToString(), 10f, (FontStyle.Italic | FontStyle.Bold));

            }

        Label_0194:
            e.Graphics.DrawString(this.m_SampleText, font1, brush2, ((float)num1), ((float)num2));
            font1.Dispose();

        }
开发者ID:dbbotkin,项目名称:PrimeComm,代码行数:62,代码来源:FontBrowser.cs

示例11: UpdateFontStyle

        private void UpdateFontStyle()
        {
            chkStrikeout.Checked = (selectedFont.Style & FontStyle.Strikeout) == FontStyle.Strikeout;
            chkUnderline.Checked = (selectedFont.Style & FontStyle.Underline) == FontStyle.Underline;

            styleList.Items.Clear();

            if (string.IsNullOrEmpty(selectedFont.Name))
            {
                styleList.Enabled = false;
            }
            else
            {
                styleList.Enabled = true;

                using (FontFamily ff = new FontFamily(selectedFont.Name))
                {
                    if (ff.IsStyleAvailable(FontStyle.Regular))
                        styleList.Items.Add("Regular");

                    if (ff.IsStyleAvailable(FontStyle.Italic))
                        styleList.Items.Add("Italic");

                    if (ff.IsStyleAvailable(FontStyle.Bold))
                        styleList.Items.Add("Bold");

                    if (ff.IsStyleAvailable(FontStyle.Bold | FontStyle.Italic))
                        styleList.Items.Add("Bold Italic");

                    chkStrikeout.Enabled = ff.IsStyleAvailable(FontStyle.Strikeout);
                    if (!chkStrikeout.Enabled) chkStrikeout.Checked = false;

                    chkUnderline.Enabled = ff.IsStyleAvailable(FontStyle.Underline);
                    if (!chkUnderline.Enabled) chkUnderline.Checked = false;

                    int foundOldStyle = -1;
                    for (int i = 0; i < styleList.Items.Count; i++)
                    {
                        string text = Convert.ToString(styleList.Items[i]);
                        FontStyle fs = FontToolkit.GetFontStyleByName(text,
                            "italic", "bold");
                        if (fs == SelectedFont.Style)
                        {
                            styleList.SelectedIndex = foundOldStyle = i;
                            break;
                        }
                    }

                    if (foundOldStyle == -1 && styleList.Items.Count > 0)
                    {
                        styleList.SelectedIndex = 0;
                        selectedFont.Style = FontToolkit.GetFontStyleByName(Convert.ToString(styleList.Items[0]),
                            "italic", "bold");

                        if (chkUnderline.Checked) selectedFont.Style |= FontStyle.Underline;
                        if (chkStrikeout.Checked) selectedFont.Style |= FontStyle.Strikeout;
                    }
                }
            }

            txtStyle.Text = FontToolkit.GetFontStyleName(selectedFont.Style,
                            "Regular", "Italic", "Bold");

            labSample.Invalidate();
        }
开发者ID:devfinity-fx,项目名称:cpms_z,代码行数:65,代码来源:FontSettingsControl.cs

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

示例13: cbxFamily_SelectedIndexChanged

    private void cbxFamily_SelectedIndexChanged(object sender, System.EventArgs e)
    {
      if (this.inModelToView)
        return;
      int idx = this.cbxFamily.SelectedIndex;
      if (idx >= 0)
      {
        this.fontProperty.FamilyName = this.cbxFamily.SelectedItem.ToString();
        FontFamily family = new FontFamily(this.fontProperty.FamilyName);
        
        string supportedSyles = "";
        if (family.IsStyleAvailable(FontStyle.Regular))
          supportedSyles += "Regualr, ";
        if (family.IsStyleAvailable(FontStyle.Bold))
          supportedSyles += "Bold, ";
        if (family.IsStyleAvailable(FontStyle.Italic))
          supportedSyles += "Italic, ";
        if (family.IsStyleAvailable(FontStyle.Bold | FontStyle.Italic))
          supportedSyles += "BoldItalic, ";
        if (family.IsStyleAvailable(FontStyle.Strikeout))
          supportedSyles += "Strikeout, ";
        if (family.IsStyleAvailable(FontStyle.Underline))
          supportedSyles += "Underline, ";
        this.lblSupportedStyles.Text = supportedSyles;

        OnUpdateDrawing();
      }
    }
开发者ID:dankennedy,项目名称:PDFSharp,代码行数:28,代码来源:FontPage.cs

示例14: IsFontFamilyFixedPitch

		private bool IsFontFamilyFixedPitch (FontFamily family)
		{
			FontStyle fs;
			
			if (family.IsStyleAvailable (FontStyle.Regular))
				fs = FontStyle.Regular;
			else if (family.IsStyleAvailable (FontStyle.Bold))
				fs = FontStyle.Bold;
			else if (family.IsStyleAvailable (FontStyle.Italic))
				fs = FontStyle.Italic;
			else if (family.IsStyleAvailable (FontStyle.Strikeout))
				fs = FontStyle.Strikeout;
			else if (family.IsStyleAvailable (FontStyle.Underline))
				fs = FontStyle.Underline;
			else
				return false;

			Font f = new Font (family.Name, 10, fs);

			if (TextRenderer.MeasureString ("i", f).Width == TextRenderer.MeasureString ("w", f).Width)
				return true;
				
			return false;
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:24,代码来源:FontDialog.cs

示例15: SetAttributeValue


//.........这里部分代码省略.........
            if (propertyName == XMLServicesConstants.XmlNodeEnableAtt)
            {
                if ((value.Equals(true.ToString().ToLower())))
                    control.Enabled = true;
                else
                    control.Enabled = false;
            }
            if (propertyName == XMLServicesConstants.XmlNodeAlignAtt)
            {
                if (control is IContainerControl)
                {
                    ((IContainerControl)control).Align = getContainerAlignment(value); //(value == ContainerAlignment.Center.ToString().ToLower())?ContainerAlignment.Center:(value == ContainerAlignment.Left.ToString().ToLower())?ContainerAlignment.Left:ContainerAlignment.Right;
                }
            }

            if (propertyName == XMLServicesConstants.XmlNodePositionAtt)
            {
                ((IEIBControl)control).Position = (value == ControlPosition.Absolute.ToString().ToLower()) ? ControlPosition.Absolute : ControlPosition.Relative;
            }

            if (propertyName == XMLServicesConstants.XmlNodeFontSizeAtt)
            {
                control.Font = new Font(control.Font.FontFamily, float.Parse(value),control.Font.Style);
            }
            if (propertyName == XMLServicesConstants.XmlNodeFontStyleAtt)
            {
                FontStyle fs=GetFontStyle(value);
                control.Font = new Font(control.Font,fs );
            }
            if (propertyName == XMLServicesConstants.XmlNodeFontAtt)
            {

                     FontFamily f = new FontFamily(value);
                     if (f.IsStyleAvailable(control.Font.Style))
                     {
                         control.Font = new Font(value, control.Font.Size, control.Font.Style);
                     }
                     else
                     {
                         MessageBox.Show("Font style not supported for  " +(value.ToString().Trim()) + "  for control  " +(control.Text.ToString())  );
                     }
            }
            if (propertyName == XMLServicesConstants.XmlNodeNetBackColorAtt)
            {
                if (!value.Contains("#"))
                {
                    control.BackColor = Color.FromName(value);
                }
                else
                {
                    control.BackColor = ColorTranslator.FromHtml(value);
                }
            }
            if (propertyName == XMLServicesConstants.XmlNodeNetForeColorAtt)
            {
                if (!value.Contains("#"))
                {
                    control.ForeColor = Color.FromName(value);
                }
                else
                {
                    control.ForeColor = ColorTranslator.FromHtml(value);
                }
            }
            if (propertyName == XMLServicesConstants.XmlNodeTimeAtt)
            {
开发者ID:harpreetoxyent,项目名称:pnl,代码行数:67,代码来源:EIBDeserializeServices.cs


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