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


C# ButtonItem.GetFont方法代码示例

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


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

示例1: PaintButton

		public static void PaintButton(ButtonItem button, ItemPaintArgs pa)
		{
			System.Drawing.Graphics g=pa.Graphics;
			ThemeToolbar theme=pa.ThemeToolbar;
			ThemeToolbarParts part=ThemeToolbarParts.Button;
			ThemeToolbarStates state=ThemeToolbarStates.Normal;
			Color textColor=ButtonItemPainterHelper.GetTextColor(button,pa);

			Rectangle rectImage=Rectangle.Empty;
			Rectangle itemRect=button.DisplayRectangle;
			
			Font font=null;
			CompositeImage image=button.GetImage();

			font=button.GetFont(pa, false);

			eTextFormat format= GetStringFormat(button, pa, image);

			bool bSplitButton=(button.SubItems.Count>0 || button.PopupType==ePopupType.Container) && button.ShowSubItems && !button.SubItemsRect.IsEmpty;

			if(bSplitButton)
				part=ThemeToolbarParts.SplitButton;

			// Calculate image position
			if(image!=null)
			{
				if(button.ImagePosition==eImagePosition.Top || button.ImagePosition==eImagePosition.Bottom)
					rectImage=new Rectangle(button.ImageDrawRect.X,button.ImageDrawRect.Y,itemRect.Width,button.ImageDrawRect.Height);
				else
					rectImage=new Rectangle(button.ImageDrawRect.X,button.ImageDrawRect.Y,button.ImageDrawRect.Width,button.ImageDrawRect.Height);

				rectImage.Offset(itemRect.Left,itemRect.Top);
				rectImage.Offset((rectImage.Width-button.ImageSize.Width)/2,(rectImage.Height-button.ImageSize.Height)/2);
				rectImage.Width=button.ImageSize.Width;
				rectImage.Height=button.ImageSize.Height;
			}

			// Set the state and text brush
			if(!ButtonItemPainter.IsItemEnabled(button, pa))
			{
				state=ThemeToolbarStates.Disabled;
			}
			else if(button.IsMouseDown)
			{
				state=ThemeToolbarStates.Pressed;
			}
			else if(button.IsMouseOver && button.Checked)
			{
				state=ThemeToolbarStates.HotChecked;
			}
			else if(button.IsMouseOver || button.Expanded)
			{
				state=ThemeToolbarStates.Hot;
			}
			else if(button.Checked)
			{
				state=ThemeToolbarStates.Checked;
			}
			
			Rectangle backRect=button.DisplayRectangle;
			if(button.HotTrackingStyle==eHotTrackingStyle.Image && image!=null)
			{
				backRect=rectImage;
				backRect.Inflate(3,3);
			}
			else if(bSplitButton)
			{
				backRect.Width=backRect.Width-button.SubItemsRect.Width;
			}

			// Draw Button Background
			if(button.HotTrackingStyle!=eHotTrackingStyle.None)
			{
				theme.DrawBackground(g,part,state,backRect);
			}

			// Draw Image
			if(image!=null && button.ButtonStyle!=eButtonStyle.TextOnlyAlways)
			{
				if(state==ThemeToolbarStates.Normal && button.HotTrackingStyle==eHotTrackingStyle.Color)
				{
					// Draw gray-scale image for this hover style...
					float[][] array = new float[5][];
					array[0] = new float[5] {0.2125f, 0.2125f, 0.2125f, 0, 0};
					array[1] = new float[5] {0.5f, 0.5f, 0.5f, 0, 0};
					array[2] = new float[5] {0.0361f, 0.0361f, 0.0361f, 0, 0};
					array[3] = new float[5] {0,       0,       0,       1, 0};
					array[4] = new float[5] {0.2f,    0.2f,    0.2f,    0, 1};
					System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array);
					System.Drawing.Imaging.ImageAttributes att = new System.Drawing.Imaging.ImageAttributes();
					att.SetColorMatrix(grayMatrix);
					//g.DrawImage(image,rectImage,0,0,image.Width,image.Height,GraphicsUnit.Pixel,att);
					image.DrawImage(g,rectImage,0,0,image.Width,image.Height,GraphicsUnit.Pixel,att);
				}
				else if(state==ThemeToolbarStates.Normal && !image.IsIcon)
				{
					// Draw image little bit lighter, I decied to use gamma it is easy
					System.Drawing.Imaging.ImageAttributes lightImageAttr = new System.Drawing.Imaging.ImageAttributes();
					lightImageAttr.SetGamma(.7f,System.Drawing.Imaging.ColorAdjustType.Bitmap);
					//g.DrawImage(image,rectImage,0,0,image.Width,image.Height,GraphicsUnit.Pixel,lightImageAttr);
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例2: Paint

        public void Paint(ButtonItem item, ItemPaintArgs pa, CrumbBarItemViewColorTable itemColorTable)
        {
            Graphics g =pa.Graphics;

            CrumbBarItemViewStateColorTable stateTable = itemColorTable.Default;
            CrumbBarItemViewStateColorTable stateTable2 = null;
            bool isPressed = false;
            if (item.IsMouseDown || item.Expanded)
            {
                stateTable = itemColorTable.Pressed;
                isPressed = true;
            }
            else if (item.IsMouseOverExpand)
            {
                stateTable = itemColorTable.MouseOverInactive;
                stateTable2 = itemColorTable.MouseOver;
            }
            else if (item.IsMouseOver)
                stateTable = itemColorTable.MouseOver;
            
            Rectangle rect = item.DisplayRectangle;
            rect.Width--;
            rect.Height--;
            Rectangle expandRect = item.GetTotalSubItemsRect();
            if (!expandRect.IsEmpty)
            {
                expandRect.Offset(rect.Location);
                expandRect.Width--;
                expandRect.Height--;
            }

            PaintBackground(item, g, stateTable, stateTable2, isPressed, ref rect, ref expandRect);

            Color textColor = stateTable.Foreground;
            if (!item.ForeColor.IsEmpty)
                textColor = item.ForeColor;
            if (!textColor.IsEmpty)
            {
                // Render text
                Font font = item.GetFont(pa, false);
                bool rightToLeft = pa.RightToLeft;
                rect = GetTextRectangle(item);
                eTextFormat stringFormat = eTextFormat.Left | eTextFormat.VerticalCenter | eTextFormat.HidePrefix;
                if (item.TextMarkupBody == null)
                {
                    TextDrawing.DrawString(g, ButtonItemPainter.GetDrawText(item.Text), font, textColor, rect, stringFormat);
                }
                else
                {
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, textColor, rightToLeft);
                    d.HotKeyPrefixVisible = !((stringFormat & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
                    d.ContextObject = item;
                    Rectangle mr = new Rectangle(rect.X, rect.Y + (rect.Height - item.TextMarkupBody.Bounds.Height) / 2 + 1, item.TextMarkupBody.Bounds.Width, item.TextMarkupBody.Bounds.Height);
                    item.TextMarkupBody.Bounds = mr;
                    item.TextMarkupBody.Render(d);
                }

                if ((item.SubItems.Count > 0 || item.PopupType == ePopupType.Container) && item.ShowSubItems)
                {
                    // Render expand sign
                    GraphicsPath path = GetExpandPath(item, expandRect);
                    if (path != null)
                    {
                        SmoothingMode sm = g.SmoothingMode;
                        g.SmoothingMode = SmoothingMode.Default;
                        using(Brush brush=new SolidBrush(stateTable.Foreground))
                            g.FillPath(brush, path);
                        g.SmoothingMode = sm;
                    }
                }
            }
        }
开发者ID:huamanhtuyen,项目名称:VNACCS,代码行数:72,代码来源:CrumbBarItemViewPainter.cs

示例3: LayoutButtonX

        public static void LayoutButtonX(ButtonItem button)
        {
            Control objCtrl = button.ContainerControl as Control;
            ButtonX btnX = button.ContainerControl as ButtonX;
            if (!BarFunctions.IsHandleValid(objCtrl))
                return;
            bool isOnMenu = button.IsOnMenu;
            if (isOnMenu && button.Parent is ItemContainer)
                isOnMenu = false;
            bool bHasImage = false;

            if (!string.IsNullOrEmpty(button.Symbol))
            {
                bHasImage = true;
            }
            else
            {
                using (CompositeImage buttonImage = button.GetImage())
                {
                    if (buttonImage != null)
                        bHasImage = true;
                }
            }

            eImagePosition imagePosition = button.ImagePosition;
            bool rightToLeft = (objCtrl.RightToLeft == RightToLeft.Yes);

            Rectangle textDrawRect = Rectangle.Empty;
            Rectangle imageDrawRect = Rectangle.Empty;
            Rectangle subItemsRect = Rectangle.Empty;
            Rectangle bounds = button.Bounds;

            // Calculate sub-items rectangle
            if (button.SubItems.Count > 0 && button.ShowSubItems &&
                        !(button.TextMarkupBody != null && button.TextMarkupBody.HasExpandElement && button.ButtonStyle != eButtonStyle.Default))
            {
                // Add small button to expand the item
                if (button.Orientation == eOrientation.Horizontal)
                {
                    if (rightToLeft)
                        subItemsRect = new Rectangle(0, 0, button.SubItemsExpandWidth, bounds.Height);
                    else
                        subItemsRect = new Rectangle(bounds.Width - button.SubItemsExpandWidth, 0, button.SubItemsExpandWidth, bounds.Height);
                    if (rightToLeft)
                        bounds.X += button.SubItemsExpandWidth + 1;
                    bounds.Width -= button.SubItemsExpandWidth + 1;
                }
                else
                {
                    subItemsRect = new Rectangle(0, bounds.Height - button.SubItemsExpandWidth, bounds.Width, button.SubItemsExpandWidth);
                    bounds.Height -= button.SubItemsExpandWidth + 1;
                }
            }

            // Adjust image position
            if (rightToLeft && button.Orientation == eOrientation.Horizontal)
            {
                if (imagePosition == eImagePosition.Left)
                    imagePosition = eImagePosition.Right;
                else if (imagePosition == eImagePosition.Right)
                    imagePosition = eImagePosition.Left;
            }

            int measureStringWidth = 0;

            measureStringWidth = bounds.Width;

            Graphics g = BarFunctions.CreateGraphics(objCtrl);
            try
            {

                // Get the right image size that we will use for calculation
                Size imageSize = Size.Empty;
                if (!string.IsNullOrEmpty(button.Symbol))
                {
                    Font symFont = Symbols.GetFontAwesome(button.SymbolSize);
                    imageSize = TextDrawing.MeasureStringLegacy(g, button.Symbol, symFont, Size.Empty, eTextFormat.Default);
                    int descent = (int)Math.Ceiling((symFont.FontFamily.GetCellDescent(symFont.Style) *
                    symFont.Size / symFont.FontFamily.GetEmHeight(symFont.Style)));
                    imageSize.Height -= descent;
                    button.ImageSize = imageSize;
                }
                else
                {
                    if (!button.ImageFixedSize.IsEmpty)
                        imageSize = button.ImageFixedSize;
                    else
                        imageSize = button.ImageSize;
                }

                if (bHasImage && (imagePosition == eImagePosition.Left || imagePosition == eImagePosition.Right))
                {
                    if (btnX != null)
                        measureStringWidth -= imageSize.Width + btnX.ImageTextSpacing * 2 + 3;
                    else
                        measureStringWidth -= (imageSize.Width + 8);
                }

                if (bHasImage && !imageSize.IsEmpty && btnX != null && btnX.ImageTextSpacing != 0)
                {
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例4: PaintButtonText

		public override void PaintButtonText(ButtonItem button, ItemPaintArgs pa, Color textColor, CompositeImage image)
		{
            if (!button.RenderText) return;
			Graphics g=pa.Graphics;
			eTextFormat stringFormat=GetStringFormat(button,pa,image);
            bool isOnMenu = IsOnMenu(button, pa);
			bool isOnMenuBar=pa.IsOnMenuBar;
			
            Rectangle itemRect=button.DisplayRectangle;
			Rectangle rect=GetTextRectangle(button, pa, stringFormat, image);
			
			Font font=button.GetFont(pa, false);
            bool rightToLeft = pa.RightToLeft;

            //if (isOnMenu && rightToLeft || (stringFormat & eTextFormat.Left) == eTextFormat.Left)
            //    stringFormat |=eTextFormat.Right;

			// Draw menu item text
            if (isOnMenu || button.ButtonStyle != eButtonStyle.Default || image == null && string.IsNullOrEmpty(button.Symbol) || (!isOnMenu && (button.ImagePosition == eImagePosition.Top || button.ImagePosition == eImagePosition.Bottom)))
			{
				if(button.Orientation==eOrientation.Vertical && !isOnMenu)
				{
					g.RotateTransform(90);
                    if (button.TextMarkupBody == null)
                    {
                        TextDrawing.DrawStringLegacy(g, GetDrawText(button.Text), font, textColor, new Rectangle(rect.Top, -rect.Right, rect.Height, rect.Width), stringFormat);
                    }
                    else
                    {
                        TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, textColor, rightToLeft);
                        d.HotKeyPrefixVisible = !((stringFormat & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
                        button.TextMarkupBody.Bounds = new Rectangle(rect.Top, -rect.Right, button.TextMarkupBody.Bounds.Width, button.TextMarkupBody.Bounds.Height);
                        button.TextMarkupBody.Render(d);
                    }

					g.ResetTransform();
				}
				else
				{
                    if (button.TextMarkupBody == null)
                    {
						#if FRAMEWORK20
                        if (pa.GlassEnabled && (button.Parent is CaptionItemContainer || button.Parent is RibbonTabItemContainer && (button.EffectiveStyle == eDotNetBarStyle.Office2010 || button.EffectiveStyle == eDotNetBarStyle.Metro)) && !(pa.ContainerControl is QatToolbar))
                        {
                            if (!pa.CachedPaint)
                                Office2007RibbonControlPainter.PaintTextOnGlass(g, button.Text, font, rect, TextDrawing.GetTextFormat(stringFormat), textColor, true, !button.IsMouseOver && !ColorFunctions.IsEqual(textColor, Color.White), 7);
                        }
                        else
						#endif
                            TextDrawing.DrawString(g, GetDrawText(button.Text), font, textColor, rect, stringFormat);
                    }
                    else
                    {
                        TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, textColor, rightToLeft);
                        d.HotKeyPrefixVisible = !((stringFormat & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
                        d.ContextObject = button;
                        Rectangle mr = new Rectangle((rightToLeft && isOnMenu?rect.X+rect.Width-button.TextMarkupBody.Bounds.Width:rect.X), rect.Y + (rect.Height - button.TextMarkupBody.Bounds.Height) / 2 /*- (isOnMenu ? -1 : -1)*/+1, button.TextMarkupBody.Bounds.Width, button.TextMarkupBody.Bounds.Height);
                        if (pa.ContainerControl is RibbonBar && (button.ImagePosition == eImagePosition.Top || button.ImagePosition == eImagePosition.Bottom))
                            mr = new Rectangle(rect.X + (rect.Width - button.TextMarkupBody.Bounds.Width) / 2, rect.Y, button.TextMarkupBody.Bounds.Width, button.TextMarkupBody.Bounds.Height);
                        else if (IsTextCentered(button, pa, image))
                            mr.Offset((rect.Width - mr.Width) / 2, 0);
                        if (button._FixedSizeCenterText) mr.Y--;
                        button.TextMarkupBody.Bounds = mr;
                        button.TextMarkupBody.Render(d);
                    }

					if(!button.DesignMode && button.Focused && !isOnMenu && !isOnMenuBar && !(pa.ContainerControl is ButtonX && !((ButtonX)pa.ContainerControl).FocusCuesEnabled))
					{
						Rectangle r=itemRect;
                        r.Inflate(-2, -2);
						ControlPaint.DrawFocusRectangle(g,r);
					}
				}					
			}
			
			// Draw Shortcut text if needed
			if( button.DrawShortcutText!="" && isOnMenu && !button.IsOnCustomizeDialog)
			{
                stringFormat |= eTextFormat.HidePrefix;
                
                //if(rightToLeft)
                //    stringFormat = stringFormat & ~(stringFormat & eTextFormat.Right) | eTextFormat.Left;
                //else
                    stringFormat|=eTextFormat.Right;

				TextDrawing.DrawString(g, button.DrawShortcutText, font, textColor, rect, stringFormat);
			}
		}
开发者ID:,项目名称:,代码行数:88,代码来源:

示例5: LayoutButton

        public static void LayoutButton(ButtonItem button, bool startButtonType)
        {
            Control objCtrl = button.ContainerControl as Control;
            if (objCtrl == null || objCtrl.Disposing || objCtrl.IsDisposed) //if(!BarFunctions.IsHandleValid(objCtrl))
                return;
            if (objCtrl is ButtonX && button._FitContainer)
            {
                LayoutButtonX(button);
                return;
            }
            else if (button.FixedSize.Width > 0 && button.FixedSize.Height > 0)
            {
                button.SetDisplayRectangle(new Rectangle(button.DisplayRectangle.Location, button.FixedSize));
                LayoutButtonX(button);
                return;
            }

            bool isOnMenu = button.IsOnMenu;
            if (isOnMenu && button.Parent is ItemContainer)
                isOnMenu = false;
            bool bHasImage = false;
            bool isSymbolImage = false;
            if (!string.IsNullOrEmpty(button.Symbol))
            {
                bHasImage = true;
                isSymbolImage = true;
            }
            else
            {
                using (CompositeImage buttonImage = button.GetImage())
                {
                    if (buttonImage != null || startButtonType)
                        bHasImage = true;
                }
            }

            eImagePosition imagePosition = button.ImagePosition;
            bool rightToLeft = (objCtrl.RightToLeft == RightToLeft.Yes);

            Rectangle textDrawRect = Rectangle.Empty;
            Rectangle imageDrawRect = Rectangle.Empty;
            Rectangle subItemsRect = Rectangle.Empty;
            Rectangle bounds = new Rectangle(button.DisplayRectangle.Location, Size.Empty); // Critical to preserve the location for compatibility reasons

            if (rightToLeft && button.Orientation == eOrientation.Horizontal)
            {
                if (imagePosition == eImagePosition.Left)
                    imagePosition = eImagePosition.Right;
                else if (imagePosition == eImagePosition.Right)
                    imagePosition = eImagePosition.Left;
            }

            int measureStringWidth = 0;

            if (button._FitContainer)
                measureStringWidth = button.DisplayRectangle.Width - 4;

            bounds.Width = 0;
            bounds.Height = 0;

            Graphics g = BarFunctions.CreateGraphics(objCtrl);
            try
            {
                eTextFormat stringFormat = GetTextFormat(button);

                // Get the right image size that we will use for calculation
                Size imageSize = Size.Empty;
                if (isSymbolImage)
                {
                    Font symFont = Symbols.GetFontAwesome(button.SymbolSize);
                    
                    if(button.IsOnMenu) // Need to do this to get consistent size for the symbol since they are not all the same width we pick widest
                        imageSize = TextDrawing.MeasureString(g, "\uF00A", symFont);
                    else
                        imageSize = TextDrawing.MeasureString(g, button.Symbol, symFont);

                    int descent = (int)Math.Ceiling((symFont.FontFamily.GetCellDescent(symFont.Style) *
                    symFont.Size / symFont.FontFamily.GetEmHeight(symFont.Style)));
                    imageSize.Height -= descent;
                    button.ImageSize = imageSize;
                }
                else
                {
                    imageSize = GetLayoutImageSize(button, bHasImage, isOnMenu, startButtonType);
                }
                bool ribbonBarButton = false;
                if (button._FitContainer && bHasImage && (imagePosition == eImagePosition.Left || imagePosition == eImagePosition.Right))
                {
                    measureStringWidth -= (imageSize.Width + 10);
                }
                else if (button.RibbonWordWrap && bHasImage && imagePosition == eImagePosition.Top && objCtrl is RibbonBar && UseRibbonWordBreak(button))
                {
                    measureStringWidth = imageSize.Width + 4;
                    stringFormat |= eTextFormat.WordBreak;
                    ribbonBarButton = true;
                }

                // Measure string
                Font font = button.GetFont(null, true);

//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


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