示例#1
0
        protected override void PaintContent(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            SmoothingMode sm = g.SmoothingMode;
            if (AntiAlias)
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
            }

            Rectangle r = GetContentRectangle();
            Point reflectionLocation = r.Location;
            bool disposeStyle = false;
            ElementStyle style = this.GetBackgroundStyle(out disposeStyle);

            if (_TextMarkup != null)
            {
                TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, (style.TextColor.IsEmpty?this.ForeColor:style.TextColor), 
                    (this.RightToLeft == RightToLeft.Yes), Rectangle.Empty, true);
                if (!this.Enabled)
                {
                    d.IgnoreFormattingColors = true;
                    d.CurrentForeColor = SystemColors.ControlDark;
                }
                _TextMarkup.Render(d);
                reflectionLocation.Y = _TextMarkup.Bounds.Bottom;
                reflectionLocation.X = 0;
            }
            else
            {
                int totalHeight = (int)(_TextSize.Height * (1 + _ReflectionFactor));
                int y = r.Y, x = r.X;
                if (style.TextLineAlignment == eStyleTextAlignment.Center)
                {
                    y += (r.Height - totalHeight) / 2;
                }
                else if (style.TextLineAlignment == eStyleTextAlignment.Far)
                {
                    y += (r.Height - totalHeight);
                }
                TextDrawing.DrawString(g, this.Text, this.Font, (style.TextColor.IsEmpty ? this.ForeColor : style.TextColor), new Rectangle(x, y, r.Width, r.Height), GetTextFormat(style));
                reflectionLocation.Y = y + _TextSize.Height;
            }

            Rectangle rClip = new Rectangle(0, reflectionLocation.Y, this.Width, this.Height - reflectionLocation.Y);
            g.SetClip(rClip, CombineMode.Replace);

            int fontBaseOffset = (int)Math.Floor(Font.Size * Font.FontFamily.GetCellDescent(Font.Style) / Font.FontFamily.GetEmHeight(Font.Style));
            reflectionLocation.Y -= fontBaseOffset;

            if (_ReflectionBitmap != null && _ReflectionEnabled)
            {
                g.DrawImage(_ReflectionBitmap, reflectionLocation);
            }
            g.ResetClip();
            if (disposeStyle) style.Dispose();
            if (AntiAlias)
                g.SmoothingMode = sm;
        }
示例#2
0
        protected virtual void ResizeMarkup()
        {
            if (m_TextMarkup != null)
            {
                Rectangle r = this.ClientTextRectangle;
                r.Inflate(-2, 0);
                r.X += ElementStyleLayout.LeftWhiteSpace(this.Style);
                r.Width -= ElementStyleLayout.HorizontalStyleWhiteSpace(this.Style);
                r.Y += ElementStyleLayout.TopWhiteSpace(this.Style);
                r.Height -= ElementStyleLayout.VerticalStyleWhiteSpace(this.Style);
                
                if (r.Width <= 0 || r.Height <= 0)
                    return;
                Graphics g = this.CreateGraphics();
                try
                {
                    if (m_AntiAlias)
                    {
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
                    }
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, SystemColors.Control, (this.RightToLeft == RightToLeft.Yes));
                    m_TextMarkup.Measure(r.Size, d);
                    m_TextMarkup.Arrange(r, d);
                    if (this.AutoScroll)
                    {
                        Size autoScrollMinSize = Size.Empty;
                        if (m_TextMarkup.Bounds.Height > r.Height)
                            autoScrollMinSize.Height = m_TextMarkup.Bounds.Height + m_Style.MarginTop + m_Style.MarginBottom + 2;
                        if (m_TextMarkup.Bounds.Width > r.Width)
                            autoScrollMinSize.Width = m_TextMarkup.Bounds.Width + m_Style.MarginLeft + m_Style.MarginRight + 2;

                        if (this.AutoScrollMinSize != autoScrollMinSize)
                            this.AutoScrollMinSize = autoScrollMinSize;
                    }
                    else if (!this.AutoScrollMinSize.IsEmpty)
                        this.AutoScrollMinSize = Size.Empty;
                }
                finally
                {
                    g.Dispose();
                }
            }
        }
示例#3
0
		public void ShowToolTip()
		{
			if (!this.IsHandleCreated)
				this.CreateControl();

            Size sz = Size.Empty;
			// Calculate Size of the window
			Graphics g=this.CreateGraphics();

            if (m_AntiAlias)
            {
                g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            }

            try
            {
                g.PageUnit = GraphicsUnit.Pixel;
                if (m_TextMarkup == null)
                    sz = TextDrawing.MeasureString(g, GetDrawText(), this.Font, Screen.PrimaryScreen.WorkingArea.Size, GetStringFormat());
                else
                {
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, SystemColors.Control, (this.RightToLeft == RightToLeft.Yes));
                    m_TextMarkup.Measure(Screen.PrimaryScreen.WorkingArea.Size, d);
                    sz = m_TextMarkup.Bounds.Size;
                    m_TextMarkup.Arrange(new Rectangle(Point.Empty, sz), d);
                }
            }
            finally
            {
                g.SmoothingMode = SmoothingMode.Default;
                g.TextRenderingHint = TextRenderingHint.SystemDefault;
                g.Dispose();
            }
			g=null;

			Point mousePosition=System.Windows.Forms.Control.MousePosition;
			Rectangle r=new Rectangle(System.Windows.Forms.Control.MousePosition.X,System.Windows.Forms.Control.MousePosition.Y,(int)sz.Width,(int)sz.Height);
			r.Inflate(2,2);
			r.Offset(12,24);

			ScreenInformation screen=BarFunctions.ScreenFromPoint(mousePosition);
			if(screen!=null)
			{
				System.Drawing.Size layoutArea=screen.WorkingArea.Size;
				layoutArea.Width-=(int)(layoutArea.Width*.2f);

                if (r.Right > screen.WorkingArea.Right)
                {
                    r.X = r.Left - (r.Right - screen.WorkingArea.Right);
                }

                if (r.Bottom > screen.Bounds.Bottom)
                {
                    if (ReferenceRectangle.IsEmpty)
                        r.Y = mousePosition.Y - r.Height;
                    else
                    {
                        r.Y = ReferenceRectangle.Y - r.Height - 1;
                    }
                }
				
				if(r.Contains(System.Windows.Forms.Control.MousePosition.X,System.Windows.Forms.Control.MousePosition.Y))
				{
					// We have to move it out of mouse position
                    if (r.Height + System.Windows.Forms.Control.MousePosition.Y + 1 <= screen.WorkingArea.Height && (ReferenceRectangle.IsEmpty || !ReferenceRectangle.IntersectsWith(new Rectangle(r.X, System.Windows.Forms.Control.MousePosition.Y + 1, r.Width, r.Height))))
						r.Y=System.Windows.Forms.Control.MousePosition.Y+1;
					else
						r.Y=System.Windows.Forms.Control.MousePosition.Y-r.Height-1;
				}
			}

			this.Location=r.Location;
			this.ClientSize=r.Size;

			if(NativeFunctions.ShowDropShadow)
			{
				if(m_DropShadow==null)
				{
					m_DropShadow=new PopupShadow(NativeFunctions.AlphaBlendingSupported);
					m_DropShadow.CreateControl();
				}
				//m_DropShadow.Location=new Point(r.Left+4,r.Top+4);
				//m_DropShadow.Size=r.Size;
				// TODO: Bug Cannot set size and location correctly using the Size and Location because Form caption is hidden
				m_DropShadow.Hide();
			}
			NativeFunctions.SetWindowPos(this.Handle,new IntPtr(NativeFunctions.HWND_TOP),0,0,0,0,NativeFunctions.SWP_SHOWWINDOW | NativeFunctions.SWP_NOSIZE | NativeFunctions.SWP_NOACTIVATE | NativeFunctions.SWP_NOMOVE);
			if(m_DropShadow!=null)
			{
				NativeFunctions.SetWindowPos(m_DropShadow.Handle,this.Handle,r.Left+5,r.Top+5,r.Width-2,r.Height-2,NativeFunctions.SWP_SHOWWINDOW | NativeFunctions.SWP_NOACTIVATE);
				m_DropShadow.UpdateShadow();
			}
		}
        public override void Paint(CheckBoxItemRenderEventArgs e)
        {
            Graphics g = e.Graphics;
            CheckBoxItem item = e.CheckBoxItem;
            bool rtl = e.RightToLeft;
            Font font = e.Font;
            Office2007CheckBoxStateColorTable ct = this.GetCheckBoxStateColorTable(e);

            Rectangle checkBoxPosition = Rectangle.Empty;
            Rectangle textRect = Rectangle.Empty;
            eTextFormat tf = eTextFormat.Default;
            if (!(e.ItemPaintArgs != null && e.ItemPaintArgs.ContainerControl is DevComponents.DotNetBar.Controls.CheckBoxX ||
                (e.ItemPaintArgs != null && e.ItemPaintArgs.ContainerControl is ItemControl) ||
                (e.ItemPaintArgs != null && e.ItemPaintArgs.ContainerControl is Bar) ||
                (e.ItemPaintArgs != null && e.ItemPaintArgs.ContainerControl is MenuPanel)))
            {
                    tf |= eTextFormat.NoPrefix;
            }

            Size checkSignSize = item.GetCheckSignSize();

            float baselineOffsetPixels = g.DpiY / 72f * (font.SizeInPoints / font.FontFamily.GetEmHeight(font.Style) * font.FontFamily.GetCellAscent(font.Style)) + .5f;
            //float fontDescentPixels = g.DpiY / 72f * (font.SizeInPoints / font.FontFamily.GetEmHeight(font.Style) * font.FontFamily.GetCellDescent(font.Style));

            if (item.CheckBoxPosition == eCheckBoxPosition.Left && !rtl || item.CheckBoxPosition == eCheckBoxPosition.Right && rtl)
            {
                checkBoxPosition = new Rectangle(item.DisplayRectangle.X + item.CheckTextSpacing / 2,
                    item.DisplayRectangle.Y + (item.DisplayRectangle.Height - checkSignSize.Height) / 2,
                    checkSignSize.Width, checkSignSize.Height);
                textRect = new Rectangle(checkBoxPosition.Right + item.CheckTextSpacing / 2, item.DisplayRectangle.Y,
                    item.DisplayRectangle.Right - (checkBoxPosition.Right + item.CheckTextSpacing / 2), item.DisplayRectangle.Height);

                if (item.TextMarkupBody == null)
                    textRect.Y = checkBoxPosition.Bottom - (int)baselineOffsetPixels - 2;
            }
            else if (item.CheckBoxPosition == eCheckBoxPosition.Right && !rtl || item.CheckBoxPosition == eCheckBoxPosition.Left && rtl)
            {
                checkBoxPosition = new Rectangle(item.DisplayRectangle.Right - item.CheckTextSpacing / 2 - checkSignSize.Width,
                    item.DisplayRectangle.Y + (item.DisplayRectangle.Height - checkSignSize.Height) / 2,
                    checkSignSize.Width, checkSignSize.Height);
                textRect = new Rectangle(item.DisplayRectangle.X, item.DisplayRectangle.Y,
                    checkBoxPosition.X - (item.DisplayRectangle.X + item.CheckTextSpacing / 2), item.DisplayRectangle.Height);
                if (item.TextMarkupBody == null)
                    textRect.Y = checkBoxPosition.Bottom - (int)baselineOffsetPixels - 2;

                tf |= eTextFormat.Right;
            }
            else if (item.CheckBoxPosition == eCheckBoxPosition.Top)
            {
                checkBoxPosition = new Rectangle(item.DisplayRectangle.X + (item.DisplayRectangle.Width - checkSignSize.Width) / 2,
                    item.DisplayRectangle.Y + item.VerticalPadding, checkSignSize.Width, checkSignSize.Height);
                textRect = new Rectangle(item.DisplayRectangle.X, checkBoxPosition.Bottom,
                    item.DisplayRectangle.Width, item.DisplayRectangle.Bottom - checkBoxPosition.Bottom);
                tf |= eTextFormat.VerticalCenter | eTextFormat.HorizontalCenter;
            }
            else if (item.CheckBoxPosition == eCheckBoxPosition.Bottom)
            {
                checkBoxPosition = new Rectangle(item.DisplayRectangle.X + (item.DisplayRectangle.Width - checkSignSize.Width) / 2,
                    item.DisplayRectangle.Bottom - item.VerticalPadding - checkSignSize.Height - 1, checkSignSize.Width, checkSignSize.Height);
                textRect = new Rectangle(item.DisplayRectangle.X, item.DisplayRectangle.Y,
                    item.DisplayRectangle.Width, checkBoxPosition.Y - (item.DisplayRectangle.Y + item.VerticalPadding));

                tf |= eTextFormat.VerticalCenter | eTextFormat.HorizontalCenter;
            }

            if (item.CheckState == CheckState.Unchecked && item.CheckBoxImageUnChecked != null)
                g.DrawImage(item.CheckBoxImageUnChecked, checkBoxPosition);
            else if (item.CheckState == CheckState.Checked && item.CheckBoxImageChecked != null)
                g.DrawImage(item.CheckBoxImageChecked, checkBoxPosition);
            else if (item.CheckState == CheckState.Indeterminate && item.CheckBoxImageIndeterminate != null)
                g.DrawImage(item.CheckBoxImageIndeterminate, checkBoxPosition);
            else
            {
                if (item.CheckBoxStyle == eCheckBoxStyle.CheckBox)
                {
                    PaintCheckBox(g, checkBoxPosition, ct, item.CheckState);
                }
                else
                {
                    PaintRadioButton(g, checkBoxPosition, ct, item.Checked);
                }
            }

            Color textColor = ct.Text;
            if (!item.TextColor.IsEmpty) textColor = item.TextColor;
            if (item.Text != "" && !textRect.IsEmpty && !textColor.IsEmpty && item.Orientation != eOrientation.Vertical && item.TextVisible)
            {
                if (item.TextMarkupBody != null)
                {
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, textColor, rtl);
                    d.HotKeyPrefixVisible = !((tf & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
                    if ((tf & eTextFormat.VerticalCenter) == eTextFormat.VerticalCenter)
                        textRect.Y = item.TopInternal + (item.Bounds.Height - textRect.Height) / 2;
                    else if ((tf & eTextFormat.Bottom) == eTextFormat.Bottom)
                        textRect.Y += (item.Bounds.Height - textRect.Height) + 1;

                    item.TextMarkupBody.Bounds = textRect;
                    item.TextMarkupBody.Render(d);
                }
                else
                {
#if FRAMEWORK20
                    if (e.ItemPaintArgs != null && e.ItemPaintArgs.GlassEnabled && item.Parent is CaptionItemContainer && !(e.ItemPaintArgs.ContainerControl is QatToolbar))
                    {
                        if (!e.ItemPaintArgs.CachedPaint)
                            Office2007RibbonControlPainter.PaintTextOnGlass(g, item.Text, font, textRect, TextDrawing.GetTextFormat(tf));
                    }
                    else
#endif
                        TextDrawing.DrawString(g, item.Text, font, textColor, textRect, tf);
                }
            }

            if (item.Focused && item.DesignMode)
            {
                Rectangle r = item.DisplayRectangle;
                r.Inflate(-1, -1);
                DesignTime.DrawDesignTimeSelection(g, r, e.ColorScheme.ItemDesignTimeBorder);
            }
        }
示例#5
0
        private void RenderFrame(MetroRendererInfo renderingInfo, int frameIndex)
        {
            MetroTileItem item = (MetroTileItem)renderingInfo.Control;
            MetroTileFrame frame = item.Frames[frameIndex];
            MetroTileColorTable colorTable = renderingInfo.ColorTable.MetroTile;
            Graphics g = renderingInfo.PaintEventArgs.Graphics;
            Rectangle bounds = item.Bounds;
            Region clip = null;
            if (!item.DragStartPoint.IsEmpty) // When dragging tile moves with the mouse
            {
                bounds.Location = renderingInfo.ItemPaintArgs.ContainerControl.PointToClient(Control.MousePosition);
                bounds.Location.Offset(-item.DragStartPoint.X, -item.DragStartPoint.Y);
                clip = g.Clip;
                g.SetClip(bounds, CombineMode.Replace);
            }
            Control control = item.ContainerControl as Control;
            bounds.Inflate(-InflatePixels, -InflatePixels);
            if (item.IsLeftMouseButtonDown)
                bounds.Inflate(-InflatePixelsMouseDown, -InflatePixelsMouseDown);
            else if (item.IsMouseOver)
                bounds.Inflate(InflatePixels, InflatePixels);

            //if (renderingInfo.ItemPaintArgs.DragInProgress)
            //    bounds.Inflate(DragEffectInflatePixels, DragEffectInflatePixels);

            eDesignInsertPosition insertMarker = item.DesignInsertMarker;
            if (insertMarker == eDesignInsertPosition.After)
            {
                if (item.IsDesignMarkHorizontal)
                    bounds.Offset(-DragInsertOffsetPixels, 0);
                else
                    bounds.Offset(0, -DragInsertOffsetPixels);
                g.ResetClip();
            }
            else if (insertMarker == eDesignInsertPosition.Before)
            {
                if (item.IsDesignMarkHorizontal)
                    bounds.Offset(DragInsertOffsetPixels, 0);
                else
                    bounds.Offset(0, DragInsertOffsetPixels);
                g.ResetClip();
            }

            bool dispose = false;
            bool enabled = item.GetEnabled(renderingInfo.ItemPaintArgs.ContainerControl);
            ElementStyle style = ElementStyleDisplay.GetElementStyle(frame.EffectiveStyle, out dispose);

            if (bounds.Width > 2048) bounds.Width = 2048;
            if (bounds.Height > 1600) bounds.Height = 1600;

            if (enabled)
            {
                ElementStyleDisplayInfo di = new ElementStyleDisplayInfo(style, g,  bounds);
                ElementStyleDisplay.Paint(di);
            }
            else
            {
                using (SolidBrush brush = new SolidBrush(item.DisabledBackColor.IsEmpty ? renderingInfo.ColorTable.MetroPartColors.CanvasColorLighterShade : item.DisabledBackColor))
                    g.FillRectangle(brush, bounds);
            }

            Rectangle textRect = bounds;
            textRect.X += style.PaddingLeft;
            textRect.Y += style.PaddingTop;
            textRect.Width -= style.PaddingHorizontal;
            textRect.Height -= style.PaddingVertical;
            if(item.IsMouseOver)
                textRect.Inflate(-InflatePixels, -InflatePixels);
            if (item.SubItems.Count > 0 && frameIndex < item.SubItems.Count)
            {
                BaseItem child = item.SubItems[frameIndex];
                if (child.Displayed)
                {
                    child.TopInternal = bounds.Y + style.PaddingTop + ((bounds.Height - style.PaddingTop - frame.TitleTextBounds.Height) - child.HeightInternal) / 2;
                    child.LeftInternal = bounds.X + style.PaddingLeft;
                    child.WidthInternal = item.TileSize.Width - style.PaddingHorizontal;
                    child.Paint(renderingInfo.ItemPaintArgs);
                }
            }

            Image image = frame.Image;
            ContentAlignment imageTextAlign = frame.ImageTextAlignment;
            Color textColor = enabled ? style.TextColor : renderingInfo.ColorTable.MetroPartColors.CanvasColorLightShade;
            Color symbolColor = textColor;
            if (!frame.SymbolColor.IsEmpty) symbolColor = frame.SymbolColor;
            if (image != null || !string.IsNullOrEmpty(frame.Symbol))
            {
                Font symFont = null;
                Rectangle imageRect = Rectangle.Empty;
                if (string.IsNullOrEmpty(frame.Symbol))
                    imageRect = new Rectangle(0, 0, image.Width, image.Height);
                else
                {
                    symFont = Symbols.GetFontAwesome(frame.SymbolSize);
                    Size imageSize = TextDrawing.MeasureString(g, frame.Symbol, symFont);
                    int descent = (int)Math.Ceiling((symFont.FontFamily.GetCellDescent(symFont.Style) *
                        symFont.Size / symFont.FontFamily.GetEmHeight(symFont.Style)));
                    imageSize.Height -= descent;
                    imageRect = new Rectangle(0, 0, imageSize.Width, imageSize.Height);
                }

                imageRect.Offset(bounds.Location);

                if (imageTextAlign == ContentAlignment.TopLeft)
                {
                    textRect.X += (imageRect.Width + frame.ImageIndent.X);
                    textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
                    imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
                }
                else if (imageTextAlign == ContentAlignment.TopCenter)
                {
                    imageRect.X += (item.TileSize.Width - imageRect.Width) / 2;
                    imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
                    textRect.Y += (imageRect.Height + frame.ImageIndent.Y);
                    textRect.Height -= (imageRect.Height);
                }
                else if (imageTextAlign == ContentAlignment.TopRight)
                {
                    imageRect.X += (item.TileSize.Width - imageRect.Width - frame.ImageIndent.X);
                    imageRect.Offset(0, frame.ImageIndent.Y);
                    textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
                }
                else if (imageTextAlign == ContentAlignment.BottomCenter)
                {
                    imageRect.Offset((item.TileSize.Width - imageRect.Width) / 2, item.TileSize.Height - imageRect.Height);
                    imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
                    textRect.Height -= (imageRect.Height);
                }
                else if (imageTextAlign == ContentAlignment.BottomLeft)
                {
                    imageRect.Offset(0, item.TileSize.Height - imageRect.Height);
                    imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
                    textRect.X += (imageRect.Width + frame.ImageIndent.X);
                    textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
                }
                else if (imageTextAlign == ContentAlignment.BottomRight)
                {
                    imageRect.Offset((item.TileSize.Width - imageRect.Width - frame.ImageIndent.X), item.TileSize.Height - imageRect.Height);
                    imageRect.Offset(0, frame.ImageIndent.Y);
                    textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
                }
                else if (imageTextAlign == ContentAlignment.MiddleCenter)
                {
                    imageRect.Offset((item.TileSize.Width - imageRect.Width) / 2, (item.TileSize.Height - imageRect.Height) / 2);
                    imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
                    textRect.Height = Math.Max(0, textRect.Bottom - imageRect.Bottom);
                    textRect.Y = imageRect.Bottom + 1;
                }
                else if (imageTextAlign == ContentAlignment.MiddleLeft)
                {
                    imageRect.Offset(0, (item.TileSize.Height - imageRect.Height) / 2);
                    imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
                    textRect.X += (imageRect.Width + frame.ImageIndent.X);
                    textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
                }
                else if (imageTextAlign == ContentAlignment.MiddleRight)
                {
                    imageRect.Offset((item.TileSize.Width - imageRect.Width - frame.ImageIndent.X), (item.TileSize.Height - imageRect.Height) / 2);
                    imageRect.Offset(0, frame.ImageIndent.Y);
                    textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
                }
                else
                    imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);

                if (string.IsNullOrEmpty(frame.Symbol))
                    g.DrawImage(image, imageRect);
                else
                    TextDrawing.DrawStringLegacy(g, frame.Symbol, symFont, symbolColor, new Rectangle(imageRect.X, imageRect.Y, 0, 0), eTextFormat.Default);
            }

            if (textRect.Width > 0 && textRect.Height > 0 && frame.Text != null)
            {
                Font font = renderingInfo.DefaultFont;
                if (style.Font != null)
                    font = style.Font;
                bool rightToLeft = renderingInfo.RightToLeft;
                if (frame.TextMarkupBody == null)
                {
                    eTextFormat textFormat = eTextFormat.Default | eTextFormat.WordBreak | eTextFormat.NoClipping;
                    if (style.TextLineAlignment == eStyleTextAlignment.Center)
                        textFormat |= eTextFormat.VerticalCenter;
                    else if (style.TextLineAlignment == eStyleTextAlignment.Far)
                        textFormat |= eTextFormat.Bottom;
                    if (style.TextAlignment == eStyleTextAlignment.Center)
                        textFormat |= eTextFormat.HorizontalCenter;
                    else if (style.TextAlignment == eStyleTextAlignment.Far)
                        textFormat |= eTextFormat.Right;
                    TextDrawing.DrawString(g, frame.Text, font, textColor, textRect, textFormat);
                }
                else
                {
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, textColor, rightToLeft);
                    d.HotKeyPrefixVisible = false;
                    d.ContextObject = item;
                    frame.TextMarkupBody.Bounds = textRect;
                    frame.TextMarkupBody.Render(d);
                }
            }

            if (frame.TitleText != null)
            {
                Color titleTextColor = enabled ? frame.TitleTextColor : renderingInfo.ColorTable.MetroPartColors.CanvasColorLightShade;
                if (titleTextColor.IsEmpty)
                    titleTextColor = style.TextColor;
                Font font = item.GetTitleTextFont(frame, style, control);
                Rectangle titleTextRect = frame.TitleTextBounds;
                titleTextRect.Offset(bounds.Location);
                if (item.IsMouseOver)
                    titleTextRect.Offset(InflatePixels, InflatePixels);
                TextDrawing.DrawString(g, frame.TitleText, font, titleTextColor, titleTextRect, eTextFormat.Default | eTextFormat.SingleLine);
            }

            if (item.Checked)
            {
                Rectangle markBounds = new Rectangle(bounds.Right - CheckMarkSize.Width, bounds.Y, CheckMarkSize.Width, CheckMarkSize.Height);
                using (GraphicsPath markPath = new GraphicsPath())
                {
                    markPath.AddLine(markBounds.X, markBounds.Y, markBounds.Right - 1, markBounds.Y);
                    markPath.AddLine(markBounds.Right - 1, markBounds.Y, markBounds.Right - 1, markBounds.Bottom - 1);
                    markPath.CloseFigure();
                    using (SolidBrush brush = new SolidBrush(colorTable.CheckBackground))
                        g.FillPath(brush, markPath);
                }
                using (SolidBrush brush = new SolidBrush(colorTable.CheckForeground))
                {
                    Rectangle checkCircleBounds = new Rectangle();
                    checkCircleBounds.Size = new Size(11, 11);
                    checkCircleBounds.X = markBounds.Right - checkCircleBounds.Size.Width - 3;
                    checkCircleBounds.Y = markBounds.Y + 2;
                    using (Pen pen = new Pen(colorTable.CheckForeground, 2))
                    {
                        g.DrawEllipse(pen, checkCircleBounds);
                        g.DrawLine(pen, checkCircleBounds.X + 3, checkCircleBounds.Y + 5, checkCircleBounds.X + 6, checkCircleBounds.Y + 8);
                        g.DrawLine(pen, checkCircleBounds.X + 6, checkCircleBounds.Y + 8, checkCircleBounds.X + 9, checkCircleBounds.Y + 3);
                    }
                }
            }

            if (dispose) style.Dispose();

            if (clip != null) 
            {
                g.Clip = clip;
                clip.Dispose();
            }
        }
示例#6
0
        internal Size DesiredSize(Padding margin, Rectangle parentBounds)
        {
            parentBounds.Width -= margin.Horizontal;
            parentBounds.Height -= margin.Vertical;
            parentBounds.Width -= GlowSize + TextPadding.Width * 2;
            parentBounds.Height -= GlowSize + TextPadding.Height * 2;

            Size desiredSize = new Size(GlowSize * 2 + TextPadding.Width * 2, GlowSize * 2 + TextPadding.Height * 2);

            using (Graphics g = this.CreateGraphics())
            {
                if (_TextMarkup != null)
                {
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, Color.Black, (this.RightToLeft == RightToLeft.Yes));
                    _TextMarkup.Measure(new Size(parentBounds.Width, 1), d);
                    Size textSize = _TextMarkup.Bounds.Size;
                    _TextMarkup.Arrange(new Rectangle(Point.Empty, new Size(parentBounds.Width, 1)), d);
                    textSize = _TextMarkup.Bounds.Size;
                    if (_Image != null)
                    {
                        textSize.Width += _Image.Width + TextPadding.Width;
                        textSize.Height = Math.Max(_Image.Height, textSize.Height);
                    }
                    desiredSize.Width += textSize.Width;
                    desiredSize.Height += textSize.Height;
                }
                else
                {
                    //Size textSize = TextDrawing.MeasureString(g, Text, this.Font, parentBounds.Size, TextFormat);
                    Size textSize = TextRenderer.MeasureText(Text, this.Font, parentBounds.Size, TextFormatFlags.WordBreak);
                    if (_Image != null)
                    {
                        textSize.Width += _Image.Width + TextPadding.Width;
                        textSize.Height = Math.Max(_Image.Height, textSize.Height);
                    }
                    desiredSize.Width += textSize.Width;
                    desiredSize.Height += textSize.Height;
                }
            }

            return desiredSize;
        }
示例#7
0
        protected virtual void ResizeMarkup()
        {
            if (_TextMarkup != null)
            {
                Rectangle r = this.GetContentRectangle();
                if (r.Width <= 0 || r.Height <= 0)
                    return;

                Graphics g = this.CreateGraphics();
                try
                {
                    if (AntiAlias)
                    {
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
                    }
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, SystemColors.Control, (this.RightToLeft == RightToLeft.Yes));
                    Size measureSize = new Size(10000, r.Height);
                    _TextMarkup.Measure(measureSize, d);
                    bool disposeStyle = false;
                    ElementStyle style = this.GetBackgroundStyle(out disposeStyle);

                    int totalHeight = (int)(_TextMarkup.Bounds.Height * (1 + _ReflectionFactor));
                    if (totalHeight < r.Height)
                    {
                        if (style.TextLineAlignment == eStyleTextAlignment.Center)
                        {
                            r.Y += (r.Height - totalHeight) / 2;
                            r.Height = _TextMarkup.Bounds.Height;
                        }
                        else if (style.TextLineAlignment == eStyleTextAlignment.Far)
                        {
                            r.Y = (r.Bottom - totalHeight);
                            r.Height = _TextMarkup.Bounds.Height;
                        }
                    }

                    if (_TextMarkup.Bounds.Width < r.Width)
                    {
                        if (style.TextAlignment == eStyleTextAlignment.Center)
                        {
                            r.X += (r.Width - _TextMarkup.Bounds.Width) / 2;
                            r.Width = _TextMarkup.Bounds.Width;
                        }
                        else if (style.TextAlignment == eStyleTextAlignment.Far && this.RightToLeft == RightToLeft.No ||
                            style.TextAlignment == eStyleTextAlignment.Near && this.RightToLeft == RightToLeft.Yes)
                        {
                            r.X = (r.Right - _TextMarkup.Bounds.Width);
                            r.Width = _TextMarkup.Bounds.Width;
                        }
                    }

                    _TextMarkup.Arrange(r, d);

                    if (disposeStyle) style.Dispose();
                }
                finally
                {
                    g.Dispose();
                }
            }
        }
示例#8
0
        private Size GetAutoSize()
        {
            Padding headerPadding = GetHeaderPadding();
            Padding footerPadding = GetFooterPadding();
            Padding textPadding = GetTextPadding();
            Padding imagePadding = GetImagePadding();

            Size size = Size.Empty;

            Font font = this.Font;
            if (this.Style.Font != null)
                font = this.Style.Font;

            Font headerFont = new Font(font, (m_ShowTooltipDescription || m_HeaderText == "") ? FontStyle.Bold : FontStyle.Regular);
            Graphics g = this.CreateGraphics();

            if (this.AntiAlias)
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
            }

            try
            {
                if (m_HeaderText != "" && HeaderVisible)
                {
                    Size headerSize = Size.Empty;
                    if (m_HeaderMarkup == null)
                    {
                        headerSize = TextDrawing.MeasureString(g, m_HeaderText, headerFont);
                    }
                    else
                    {
                        TextMarkup.MarkupDrawContext d=new TextMarkup.MarkupDrawContext(g, font, Color.Black, (this.RightToLeft==RightToLeft.Yes));
                        m_HeaderMarkup.Measure(new Size(1024, 1), d);
                        headerSize = m_HeaderMarkup.Bounds.Size;
                        m_HeaderMarkup.Arrange(new Rectangle(Point.Empty, headerSize), d);
                        headerSize = m_HeaderMarkup.Bounds.Size;
                    }
					headerSize.Width+=2;
					headerSize.Height+=2;
                    headerSize.Width += headerPadding.Horizontal;
                    headerSize.Height += headerPadding.Vertical;
                    if (headerSize.Width > size.Width)
                        size.Width = headerSize.Width;
                    size.Height += headerSize.Height;
                }

                if (m_FooterText != "" && FooterVisible && (m_ShowTooltipDescription || m_HeaderText == ""))
                {
                    Size footerSize = Size.Empty;
                    if (m_FooterMarkup == null)
                    {
                        footerSize = TextDrawing.MeasureString(g, m_FooterText, headerFont);
                    }
                    else
                    {
                        TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, Color.Black, (this.RightToLeft == RightToLeft.Yes));
                        m_FooterMarkup.Measure(new Size(1024, 1), d);
                        footerSize = m_FooterMarkup.Bounds.Size;
                        m_FooterMarkup.Arrange(new Rectangle(Point.Empty, footerSize), d);
                        footerSize = m_FooterMarkup.Bounds.Size;
                    }
					footerSize.Width+=2;
					footerSize.Height+=2;
                    if (m_FooterImage != null)
                    {
                        footerSize.Width += (m_FooterImage.Width + m_FooterImageSpacing);
                        if (m_FooterImage.Height > footerSize.Height)
                            footerSize.Height = m_FooterImage.Height;
                    }
                    footerSize.Width += footerPadding.Horizontal;
                    footerSize.Height += footerPadding.Vertical;
                    if (footerSize.Width > size.Width)
                        size.Width = footerSize.Width;
                    size.Height += footerSize.Height;
                }

                if (m_ShowTooltipDescription || m_HeaderText == "")
                {
                    if (this.Text != "")
                    {
                        int textArea = size.Width;
                        if (textArea < m_MinimumTooltipSize.Width)
                            textArea = m_MinimumTooltipSize.Width;
                        if (m_MaximumWidth > 0)
                            textArea = 5000;

                        Size textSize = Size.Empty;

                        if (m_BodyMarkup == null)
                        {
                            textSize = TextDrawing.MeasureString(g, this.Text, font, textArea, this.Style.TextFormat);
                            if (textSize.Height > textSize.Width * 1.75 && textSize.Width > font.Height * 2)
                            {
                                textArea = (int)(textSize.Height * .75);
                                textSize = TextDrawing.MeasureString(g, this.Text, font, textArea, this.Style.TextFormat);
                            }
                        }
                        else
                        {
                            TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, Color.Black, (this.RightToLeft == RightToLeft.Yes));
                            m_BodyMarkup.Measure(new Size(textArea, 1), d);
                            textSize = m_BodyMarkup.Bounds.Size;

                            if (textSize.Height > textSize.Width * 1.75 && textSize.Width > font.Height * 2)
                                textArea = (int)(textSize.Height * .75);

                            m_BodyMarkup.Arrange(new Rectangle(Point.Empty, new Size(textArea, 1)), d);
                            textSize = m_BodyMarkup.Bounds.Size;
                        }

                        textSize.Width += textPadding.Horizontal;
                        textSize.Height += textPadding.Vertical;

                        if (m_BodyImage != null)
                        {
                            textSize.Width += (m_BodyImage.Width + imagePadding.Horizontal);
                            if (m_BodyImage.Height + imagePadding.Vertical > textSize.Height)
                                textSize.Height = (m_BodyImage.Height + imagePadding.Vertical);
                        }

                        if (textSize.Width > size.Width)
                            size.Width = textSize.Width;
                        size.Height += textSize.Height;
                    }
                    else
                    {
                        if (m_BodyImage != null)
                        {
                            if (m_BodyImage.Width + imagePadding.Horizontal > size.Width)
                                size.Width = (m_BodyImage.Width + imagePadding.Horizontal);
                            size.Height += (m_BodyImage.Height + imagePadding.Vertical);
                        }
                    }
                }
            }
            finally
            {
                g.Dispose();
                headerFont.Dispose();
            }

            size.Width += ElementStyleLayout.HorizontalStyleWhiteSpace(this.Style);
            size.Height += ElementStyleLayout.VerticalStyleWhiteSpace(this.Style);

            if (size.Width < m_MinimumTooltipSize.Width)
                size.Width = m_MinimumTooltipSize.Width;
            if (size.Height < m_MinimumTooltipSize.Height)
                size.Height = m_MinimumTooltipSize.Height;

            return size;
        }
示例#9
0
        public override void PaintCaptionText(RibbonControlRendererEventArgs e)
        {
            RibbonStrip rs = e.RibbonControl.RibbonStrip;
            if (!rs.CaptionVisible || rs.CaptionBounds.IsEmpty)
                return;

            Graphics g = e.Graphics;
            bool isMaximized = false;
            bool isFormActive = true;
            Rendering.Office2007FormStateColorTable formct = m_ColorTable.Form.Active;
            System.Windows.Forms.Form form = rs.FindForm();
            bool renderText = true;
            if (form is RibbonForm && !((RibbonForm)form).RenderFormText) renderText = false;

            if (form != null && (form != System.Windows.Forms.Form.ActiveForm && form.MdiParent == null ||
                form.MdiParent != null && form.MdiParent.ActiveMdiChild != form))
            {
                formct = m_ColorTable.Form.Inactive;
                isFormActive = false;
            }
            string text = e.RibbonControl.TitleText;
            string plainText = text;
            bool isTitleTextMarkup = e.RibbonControl.RibbonStrip.TitleTextMarkupBody != null;
            if (isTitleTextMarkup)
                plainText = e.RibbonControl.RibbonStrip.TitleTextMarkupBody.PlainText;
            if (form != null)
            {
                if (text == "")
                {
                    text = form.Text;
                    plainText = text;
                }
                isMaximized = form.WindowState == System.Windows.Forms.FormWindowState.Maximized;
            }

            Rectangle captionRect = rs.CaptionBounds;

            // Exclude quick access toolbar if any
            if (!rs.QuickToolbarBounds.IsEmpty)
                DisplayHelp.ExcludeEdgeRect(ref captionRect, rs.QuickToolbarBounds);
            else
            {
                BaseItem sb = e.RibbonControl.GetApplicationButton();
                if (sb != null && sb.Visible && sb.Displayed)
                    DisplayHelp.ExcludeEdgeRect(ref captionRect, sb.Bounds);
                else
                    DisplayHelp.ExcludeEdgeRect(ref captionRect, new Rectangle(0, 0, 22, 22)); // The system button in top-left corner
            }

            if (!rs.SystemCaptionItemBounds.IsEmpty)
                DisplayHelp.ExcludeEdgeRect(ref captionRect, rs.SystemCaptionItemBounds);


            // Array of the rectangles after they are split
            ArrayList rects = new ArrayList(5);
            ArrayList tempRemoveList = new ArrayList(5);
            // Exclude Context Tabs Captions if any
            if (rs.TabGroupsVisible)
            {
                foreach (RibbonTabItemGroup group in rs.TabGroups)
                {
                    foreach (Rectangle r in group.DisplayPositions)
                    {
                        if (rects.Count > 0)
                        {
                            tempRemoveList.Clear();
                            Rectangle[] arrCopy = new Rectangle[rects.Count];
                            rects.CopyTo(arrCopy);
                            for (int irc = 0; irc < arrCopy.Length; irc++)
                            {
                                if (arrCopy[irc].IntersectsWith(r))
                                {
                                    tempRemoveList.Add(irc);
                                    Rectangle[] splitRects = DisplayHelp.ExcludeRectangle(arrCopy[irc], r);
                                    rects.AddRange(splitRects);
                                }
                            }
                            foreach (int idx in tempRemoveList)
                                rects.RemoveAt(idx);
                        }
                        else
                        {
                            if (r.IntersectsWith(captionRect))
                            {
                                Rectangle[] splitRects = DisplayHelp.ExcludeRectangle(captionRect, r);
                                if (splitRects.Length > 0)
                                {
                                    rects.AddRange(splitRects);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            Font font = SystemFonts.CaptionFont;
            bool disposeFont = true;
            if (rs.CaptionFont != null)
            {
                font.Dispose();
                font = rs.CaptionFont;
                disposeFont = false;
            }
            Size textSize = Size.Empty;
            if (isTitleTextMarkup)
            {
                textSize = e.RibbonControl.RibbonStrip.TitleTextMarkupBody.Bounds.Size;
            }
            else
            {
                textSize = TextDrawing.MeasureString(g, plainText, font);
            }

            if (rects.Count > 0)
            {
                rs.CaptionTextBounds = (Rectangle[])rects.ToArray(typeof(Rectangle));
                if (e.RibbonControl.RightToLeft == System.Windows.Forms.RightToLeft.No)
                    rects.Reverse();
                captionRect = Rectangle.Empty;
                foreach (Rectangle r in rects)
                {
                    if (r.Width >= textSize.Width)
                    {
                        captionRect = r;
                        break;
                    }
                    else if (r.Width > captionRect.Width)
                        captionRect = r;
                }
            }
            else
                rs.CaptionTextBounds = new Rectangle[] { captionRect };

            if (captionRect.Width > 6 && captionRect.Height > 6 && renderText)
            {
                if (e.GlassEnabled && e.ItemPaintArgs != null && e.ItemPaintArgs.ThemeWindow != null && !e.RibbonControl.IsDesignMode)
                {
                    if (!e.ItemPaintArgs.CachedPaint || isMaximized)
                        PaintGlassText(g, plainText, font, captionRect, isMaximized);
                }
                else
                {
                    if (!isTitleTextMarkup)
                        TextDrawing.DrawString(g, plainText, font, formct.CaptionText, captionRect, eTextFormat.VerticalCenter | eTextFormat.HorizontalCenter | eTextFormat.EndEllipsis | eTextFormat.NoPrefix);
                    else
                    {
                        TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, formct.CaptionText, e.RibbonControl.RightToLeft == System.Windows.Forms.RightToLeft.Yes, captionRect, false);
                        d.AllowMultiLine = false;
                        d.IgnoreFormattingColors = !isFormActive;
                        TextMarkup.BodyElement body = e.RibbonControl.RibbonStrip.TitleTextMarkupBody;
                        if (e.RibbonControl.RibbonStrip.TitleTextMarkupLastArrangeBounds != captionRect)
                        {
                            body.Measure(captionRect.Size, d);
                            body.Arrange(captionRect, d);
                            e.RibbonControl.RibbonStrip.TitleTextMarkupLastArrangeBounds = captionRect;
                            Rectangle mr = body.Bounds;
                            if (mr.Width < captionRect.Width)
                                mr.Offset((captionRect.Width - mr.Width) / 2, 0);
                            if (mr.Height < captionRect.Height)
                                mr.Offset(0, (captionRect.Height - mr.Height) / 2);
                            body.Bounds = mr;
                        }
                        Region oldClip = g.Clip;
                        g.SetClip(captionRect, CombineMode.Intersect);
                        body.Render(d);
                        g.Clip = oldClip;
                        if (oldClip != null) oldClip.Dispose();
                    }
                }
            }

            if (disposeFont) font.Dispose();
        }
示例#10
0
        public override void Paint(ItemPaintArgs p)
        {
            Graphics g = p.Graphics;
            Rectangle bounds = this.DisplayRectangle;

            if (_Image != null)
            {
                Rectangle imageRect = GetImageRect(bounds);
                g.DrawImage(_Image, imageRect);
            }

            Rectangle contentBounds = GetContentBounds(bounds);

            // Draw shadow
            Rectangle shadowBounds = contentBounds;
            shadowBounds.Inflate(1, 0);
            shadowBounds.Offset(0, 1);
            using (GraphicsPath path = CreateCalloutPath(shadowBounds))
            {
                using (Pen pen = new Pen(Color.FromArgb(32, Color.Black)))
                    g.DrawPath(pen, path);
            }

            using (GraphicsPath path = CreateCalloutPath(contentBounds))
            {
                Brush fill = GetCalloutBrush();
                if (fill != null)
                {
                    g.FillPath(fill, path);
                    fill.Dispose();
                }
                Pen pen = GetCalloutPen();
                if (pen != null)
                {
                    g.DrawPath(pen, path);
                    pen.Dispose();
                }
            }

            Color headerColor = GetHeaderColor();
            Rectangle headerTextBounds = GetTextBounds(bounds);
            Rectangle textBounds = headerTextBounds;
            string userName = this.SourceName;
            if (!string.IsNullOrEmpty(userName))
            {
                using (Font font = new Font(p.Font, FontStyle.Bold))
                {
                    TextDrawing.DrawString(g, userName, font, headerColor, headerTextBounds, eTextFormat.Top | eTextFormat.Left);
                    textBounds.Y += font.Height + TextLineSpacing;
                    textBounds.Height -= font.Height + TextLineSpacing;
                }
            }
            if (_Created != DateTime.MinValue && _Created != DateTime.MaxValue)
            {
                TimeSpan span = DateTime.Now.Subtract(_Created);
                //Console.WriteLine("Tweet from {0} created on {1}", SourceName, _Created);
                string timeString = GetHumanTimeSpan(span);
                using (Font font = new Font(p.Font, FontStyle.Italic))
                {
                    TextDrawing.DrawString(g, timeString, font, headerColor, headerTextBounds, eTextFormat.Top | eTextFormat.Right);
                    headerTextBounds.Y += font.Height + TextLineSpacing;
                    headerTextBounds.Height -= font.Height + TextLineSpacing;
                }
            }

            string text = this.Text;
            Color textColor = GetTextColor();
            if (!string.IsNullOrEmpty(text))
            {
                Font font = p.Font;
                if (this.TextMarkupBody != null)
                {
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, textColor, p.RightToLeft);
                    d.HotKeyPrefixVisible = true;
                    this.TextMarkupBody.Bounds = textBounds;
                    this.TextMarkupBody.Render(d);
                }
                else
                    TextDrawing.DrawString(g,
                        text,
                        font,
                        textColor,
                        textBounds,
                        eTextFormat.Top | eTextFormat.Left | eTextFormat.WordBreak | eTextFormat.WordEllipsis);
            }
        }
示例#11
0
        public override void Render(MetroRendererInfo renderingInfo)
        {
            MetroTabItem tab = (MetroTabItem)renderingInfo.Control;
            Graphics g = renderingInfo.PaintEventArgs.Graphics;
            MetroTabItemColorTable cti = renderingInfo.ColorTable.MetroTab.MetroTabItem;
            MetroTabItemStateColorTable color = cti.Default;
            if (!tab.Enabled)
                color = cti.Disabled;
            else if (tab.Checked)
                color = cti.Selected;
            else if (tab.IsMouseDown && cti.Pressed != null)
                color = cti.Pressed;
            else if (tab.IsMouseOver && cti.MouseOver != null)
                color = cti.MouseOver;

            Rectangle bounds = tab.Bounds;
            Rectangle textBounds = tab.TextRenderBounds;
            Rectangle imageBounds = tab.ImageRenderBounds;
            CompositeImage image = tab.GetImage();

            if (color.Background != null)
            {
                Font font = renderingInfo.DefaultFont;
                ElementStyleDisplayInfo di = new ElementStyleDisplayInfo(color.Background, g, bounds);
                ElementStyleDisplay.Paint(di);

                if (image != null && tab.ButtonStyle != eButtonStyle.TextOnlyAlways)
                {
                    if (imageBounds.IsEmpty)
                        imageBounds = GetImageRectangle(tab, image);
                    if (textBounds.IsEmpty)
                        textBounds = GetTextRectangle(tab, image, imageBounds);

                }
                else if (textBounds.IsEmpty)
                    textBounds = bounds;

                if (tab.TextMarkupBody == null)
                {
                    di.Bounds = textBounds;
                    
                    ElementStyleDisplay.PaintText(di, tab.Text, font);
                }
                else
                {
                    eTextFormat stringFormat = eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter;
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, color.Background.TextColor, renderingInfo.RightToLeft);
                    d.HotKeyPrefixVisible = !((stringFormat & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
                    d.ContextObject = tab;
                    Rectangle mr = new Rectangle(textBounds.X, textBounds.Y + (textBounds.Height - tab.TextMarkupBody.Bounds.Height) / 2 + 1, tab.TextMarkupBody.Bounds.Width, tab.TextMarkupBody.Bounds.Height);
                    if ((stringFormat & eTextFormat.HorizontalCenter) != 0)
                        mr.Offset((textBounds.Width - mr.Width) / 2, 0);
                    if (tab._FixedSizeCenterText) mr.Y--;
                    tab.TextMarkupBody.Bounds = mr;
                    tab.TextMarkupBody.Render(d);
                }
                tab.TextRenderBounds = textBounds;
                tab.ImageRenderBounds = imageBounds;
            }

            if (image != null)
            {
                if (!tab.IsMouseOver && tab.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 };
                    ColorMatrix grayMatrix = new ColorMatrix(array);
                    ImageAttributes att = new ImageAttributes();
                    att.SetColorMatrix(grayMatrix);
                    image.DrawImage(g, imageBounds, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, att);
                }
                else
                {
                    image.DrawImage(g, imageBounds);
                }
            }

            //g.FillRectangle(Brushes.Red, bounds);
        }
示例#12
0
        /// <summary>
        /// Draws the tab text
        /// </summary>
        /// <param name="g"></param>
        /// <param name="colors"></param>
        protected virtual void DrawTabText(Graphics g, SuperTabItemStateColorTable colors)
        {
            if (TabStripItem.DisplaySelectedTextOnly == false || TabItem.IsSelected == true)
            {
                Rectangle r = TabItem.TextBounds;
                Font font = TabItem.GetTabFont();
                
                if (TabItem.IsVertical == false)
                {
                    if (TabItem.TextMarkupBody != null)
                    {
                        r = AlignText(r);

                        TextMarkup.MarkupDrawContext d =
                            new TextMarkup.MarkupDrawContext(g, font, colors.Text, TabItem.IsRightToLeft);

                        TabItem.TextMarkupBody.Arrange(new
                            Rectangle(r.Location, TabItem.TextMarkupBody.Bounds.Size), d);

                        RenderMarkup(g, r, d);
                    }
                    else
                    {
                        eTextFormat strFormat;

                        r = AlignText(r, out strFormat);

                        TextDrawing.DrawString(g, TabItem.Text, font, colors.Text, r, strFormat);
                    }
                }
                else
                {
                    if (TabItem.TextMarkupBody != null)
                    {
                        Rectangle t = TabItem.TextMarkupBody.Bounds;

                        r = SetTransform(g, r);
                        r = AlignText(r);

                        TextMarkup.MarkupDrawContext d =
                            new TextMarkup.MarkupDrawContext(g, font, colors.Text, TabItem.IsRightToLeft);

                        TabItem.TextMarkupBody.Bounds = r;
                        RenderMarkup(g, r, d);
                        TabItem.TextMarkupBody.Bounds = t;
                    }
                    else
                    {
                        eTextFormat strFormat;

                        r = SetTransform(g, r);
                        r = AlignText(r, out strFormat);

                        TextDrawing.DrawStringLegacy(g, TabItem.Text, font, colors.Text, r, strFormat);                        
                    }

                    ResetTransform(g);
                }

                if (TabDisplay.ShowFocusRectangle && TabItem.IsSelected)
                    ControlPaint.DrawFocusRectangle(g, GetFocusRectangle(TabItem.DisplayRectangle));
            }
        }
示例#13
0
        /// <summary>
        /// Draws a given date period or range
        /// </summary>
        /// <param name="e"></param>
        /// <param name="scol">Starting column</param>
        /// <param name="ecol">Ending column</param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        private void DrawDatePeriod(ItemPaintArgs e,
            int scol, int ecol, DateTime startDate, DateTime endDate)
        {
            Graphics g = e.Graphics;

            Rectangle rs = GetColumnRect(scol);
            Rectangle re = GetColumnRect(ecol);

            Rectangle r = new Rectangle(rs.X, rs.Y, re.Right - rs.X, PeriodHeaderHeight);

            // Keep us in bounds

            if (r.X < Bounds.X)
            {
                r.Width -= (Bounds.X - r.X);
                r.X = Bounds.X;
            }

            if (r.Right > Bounds.Right)
                r.Width -= (r.Right - Bounds.Right) + 1;

            if (r.Width > 0 && r.Height > 0)
            {
                // Fill the area

                using (Brush lbr =
                    _ViewColor.BrushPart((int)eCalendarWeekDayPart.DayHeaderBackground, r))
                {
                    g.FillRectangle(lbr, r);
                }

                // Format the period text and output it both
                // vertically and horizontally centered

                string text = GetDatePeriodText(ref startDate, ref endDate);

                if (_CalendarView.DoTimeLineViewRenderPeriodHeader(g, startDate, endDate, r, ref text) == false)
                {
                    if (String.IsNullOrEmpty(text) == false)
                    {
                        Text = text;

                        if (IsUsingTextMarkup)
                        {
                            TextMarkup.MarkupDrawContext d =
                                new TextMarkup.MarkupDrawContext(g, HeaderFont, _ViewColor.GetColor(
                                    (int) eCalendarWeekDayPart.DayHeaderForeground), IsRightToLeft);

                            TextMarkupBodyMeasure(new Size(5000, 5000), d);
                            
                            TextMarkupBodyArrange(new Rectangle(Point.Empty, TextMarkupBodyBounds.Size), d);

                            TextMarkupBodyBounds = AlignMarkUpText(r);

                            RenderMarkup(g, d);
                        }
                        else
                        {
                            Size sz = TextDrawing.MeasureString(g, Text, HeaderFont);

                            eTextFormat tf = eTextFormat.VerticalCenter;

                            switch (_CalendarView.TimeLinePeriodHeaderAlignment)
                            {
                                case eItemAlignment.Center:
                                    if (sz.Width < r.Width)
                                        tf |= eTextFormat.HorizontalCenter;
                                    break;

                                case eItemAlignment.Far:
                                    if (sz.Width < r.Width)
                                        tf |= eTextFormat.Right;
                                    break;
                            }

                            // Draw the text

                            TextDrawing.DrawString(g, Text, HeaderFont, _ViewColor.GetColor(
                                (int) eCalendarWeekDayPart.DayHeaderForeground), r, tf);
                        }
                    }
                }

                // Draw the border

                using (Pen pen = new Pen(
                    _ViewColor.GetColor((int)eCalendarWeekDayPart.DayHeaderBorder)))
                {
                    g.DrawRectangle(pen, r);
                }
            }
        }
示例#14
0
		protected override void OnPaint(PaintEventArgs e)
		{
            if (this.ClientRectangle.Width == 0 || this.ClientRectangle.Height == 0 || m_SuspendPaint)
                return;
            
            using (SolidBrush brush = new SolidBrush(m_CanvasColor))
                e.Graphics.FillRectangle(brush, this.ClientRectangle);

			if((m_Style.BackColor1.Color.IsEmpty || m_Style.BackColor1.Color.A<255) &&
				(m_Style.BackColor2.Color.IsEmpty || m_Style.BackColor2.Color.A<255))
			{
				base.OnPaintBackground(e);
			}

            SmoothingMode sm = e.Graphics.SmoothingMode;
            TextRenderingHint th = e.Graphics.TextRenderingHint;

			if(m_AntiAlias)
			{
				e.Graphics.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                e.Graphics.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
			}

            ItemStyle style = m_Style.Clone() as ItemStyle;
            if (m_MouseDown && this.Enabled && m_StyleMouseDown.Custom)
                style.ApplyStyle(m_StyleMouseDown);
            else if (m_MouseOver && this.Enabled && m_StyleMouseOver.Custom)
                style.ApplyStyle(m_StyleMouseOver);

            if (m_TextMarkup == null)
                RefreshTextClientRectangle();

            Rectangle r = this.DisplayRectangle; // new Rectangle(0, 0, this.Width, this.Height);
#if FRAMEWORK20
            r.X -= this.Padding.Left;
            r.Y -= this.Padding.Top;
            r.Width += this.Padding.Horizontal;
            r.Height += this.Padding.Vertical;
#else
            r.X -= this.DockPadding.Left;
            r.Y -= this.DockPadding.Top;
            r.Width += this.DockPadding.Left + this.DockPadding.Right;
            r.Height += this.DockPadding.Top + this.DockPadding.Bottom;
#endif
            Rectangle rText = m_ClientTextRectangle;
            rText.Inflate(-1, -1);

            if (!this.Enabled)
                style.ForeColor.Color = m_ColorScheme.ItemDisabledText;

            Graphics g = e.Graphics;
            
			if(IsThemed)
			{
				if(m_ThemeCachedBitmap==null || m_ThemeCachedBitmap.Size!=this.ClientRectangle.Size)
				{
					DisposeThemeCachedBitmap();
					Bitmap bmp=new Bitmap(this.ClientRectangle.Width,this.ClientRectangle.Height,e.Graphics);
					Graphics gTmp=Graphics.FromImage(bmp);
					try
					{
						this.ThemeTab.DrawBackground(gTmp,ThemeTabParts.Pane,ThemeTabStates.Normal,new Rectangle(0,0,bmp.Width,bmp.Height));
					}
					finally
					{
						gTmp.Dispose();
					}
					e.Graphics.DrawImage(bmp,0,0,bmp.Width,bmp.Height);
					if(m_Style.BackgroundImage!=null)
						BarFunctions.PaintBackgroundImage(e.Graphics,this.ClientRectangle,m_Style.BackgroundImage,m_Style.BackgroundImagePosition,m_Style.BackgroundImageAlpha);
					m_ThemeCachedBitmap=bmp;
				}
				else
				{
					e.Graphics.DrawImage(m_ThemeCachedBitmap,0,0,m_ThemeCachedBitmap.Width,m_ThemeCachedBitmap.Height);
				}

                if (this.RenderText)
                {
                    Region oldClip = g.Clip;
                    Rectangle rClip = this.ClientRectangle;
                    rClip.Inflate(-2, -2);
                    rClip.Height -= 3;
                    g.SetClip(rClip);
                    if (m_TextMarkup == null)
                        style.PaintText(g, this.Text, rText, this.Font);
                    else
                    {
                        Rectangle clip = e.ClipRectangle;
                        if (clip.Height == this.ClientRectangle.Height && clip.Width < this.ClientRectangle.Width)
                            clip.Width = this.ClientRectangle.Width;
                        TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, style.ForeColor.Color, (this.RightToLeft == RightToLeft.Yes), clip, true);
                        m_TextMarkup.Render(d);
                    }
                    g.Clip = oldClip;
                }
			}
			else
			{
                if (m_TextMarkup == null)
                {
                    if(m_RenderText)
                        style.Paint(g, r, this.Text, rText, this.Font);
                    else
                        style.Paint(g, r);
                }
                else
                {
                    style.Paint(g, r);
                    if (m_RenderText)
                    {
                        Rectangle clip = e.ClipRectangle;
                        if (clip.Height == this.ClientRectangle.Height && clip.Width < this.ClientRectangle.Width)
                            clip.Width = this.ClientRectangle.Width;
                        TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, style.ForeColor.Color, (this.RightToLeft == RightToLeft.Yes), clip, true);
                        m_TextMarkup.Render(d);
                    }
                }
			}

            if (this.Focused && m_ShowFocusRectangle)
            {
                r = this.ClientRectangle;
                r.Inflate(-2, -2);
                if (r.Width > 0 && r.Height > 0)
                    ControlPaint.DrawFocusRectangle(g, r);
            }

            e.Graphics.SmoothingMode = sm;
            e.Graphics.TextRenderingHint = th;

			base.OnPaint(e);
		}
示例#15
0
        protected virtual void ResizeMarkup()
        {
            if (m_TextMarkup != null)
            {
                Rectangle r = this.ClientTextRectangle;
                r.Inflate(-2, -2);
                r.Inflate(-(m_Style.MarginLeft + m_Style.MarginRight), -(m_Style.MarginTop + m_Style.MarginBottom));
                if (this.IsThemed)
                    r.Height -= 4;
                if (r.Width <= 0 || r.Height <= 0)
                    return;
                Graphics g = this.CreateGraphics();
                try
                {
                    if (m_AntiAlias)
                    {
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
                    }
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, SystemColors.Control, (this.RightToLeft == RightToLeft.Yes));
                    m_TextMarkup.Measure(r.Size, d);
                    if (m_MarkupUsesStyleAlignment)
                    {
                        if (m_TextMarkup.Bounds.Height < r.Height)
                        {
                            if (this.Style.LineAlignment == StringAlignment.Center)
                            {
                                r.Y += (r.Height - m_TextMarkup.Bounds.Height) / 2;
                                r.Height = m_TextMarkup.Bounds.Height;
                            }
                            else if (this.Style.LineAlignment == StringAlignment.Far)
                            {
                                r.Y = (r.Bottom - m_TextMarkup.Bounds.Height);
                                r.Height = m_TextMarkup.Bounds.Height;
                            }
                        }

                        if (m_TextMarkup.Bounds.Width < r.Width)
                        {
                            if (this.Style.Alignment == StringAlignment.Center)
                            {
                                r.X += (r.Width - m_TextMarkup.Bounds.Width) / 2;
                                r.Width = m_TextMarkup.Bounds.Width;
                            }
                            else if (this.Style.Alignment == StringAlignment.Far && this.RightToLeft == RightToLeft.No || 
                                this.Style.Alignment == StringAlignment.Near && this.RightToLeft== RightToLeft.Yes)
                            {
                                r.X = (r.Right - m_TextMarkup.Bounds.Width);
                                r.Width = m_TextMarkup.Bounds.Width;
                            }
                        }
                    }
                    
                    m_TextMarkup.Arrange(r, d);
                    if (this.AutoScroll)
                    {
                        Size autoScrollMinSize = Size.Empty;
                        if (m_TextMarkup.Bounds.Height > r.Height)
                            autoScrollMinSize.Height = m_TextMarkup.Bounds.Height + m_Style.MarginTop + m_Style.MarginBottom + 2;
                        if (m_TextMarkup.Bounds.Width > r.Width)
                            autoScrollMinSize.Width = m_TextMarkup.Bounds.Width + m_Style.MarginLeft + m_Style.MarginRight + 2;

                        if (this.AutoScrollMinSize != autoScrollMinSize)
                            this.AutoScrollMinSize = autoScrollMinSize;
                    }
                    else if (!this.AutoScrollMinSize.IsEmpty)
                        this.AutoScrollMinSize = Size.Empty;
                }
                finally
                {
                    g.Dispose();
                }
            }
        }
示例#16
0
        /// <summary>
        /// Paints insides of the control.
        /// </summary>
        /// <param name="e">Paint event arguments.</param>
        protected override void PaintInnerContent(PaintEventArgs e, ElementStyle style, bool paintText)
        {
            base.PaintInnerContent(e, style, false);
            if (!paintText)
                return;

            Rectangle r = this.ClientRectangle;
            r.X += ElementStyleLayout.LeftWhiteSpace(this.Style);
            r.Width -= ElementStyleLayout.HorizontalStyleWhiteSpace(this.Style);
            r.Y += ElementStyleLayout.TopWhiteSpace(this.Style);
            r.Height -= ElementStyleLayout.VerticalStyleWhiteSpace(this.Style);
            if (r.Width <= 4 || r.Height <= 4) return;

            Graphics g = e.Graphics;

            Font font = this.Font;
            if (this.Style.Font != null)
                font = this.Style.Font;
            Font headerFont = new Font(font, (m_ShowTooltipDescription || m_HeaderText == "") ? FontStyle.Bold : FontStyle.Regular);
            Padding headerPadding = GetHeaderPadding();
            Padding footerPadding = GetFooterPadding();
            Padding textPadding = GetTextPadding();
            Padding imagePadding = GetImagePadding();

            try
            {
                ElementStyleDisplayInfo info = new ElementStyleDisplayInfo(style, g, Rectangle.Empty);
                if (m_HeaderText != "" && HeaderVisible)
                {
                    Rectangle headerRect = new Rectangle(r.X + headerPadding.Left, r.Y + headerPadding.Top, r.Width - headerPadding.Horizontal, r.Height - headerPadding.Vertical);
                    Size headerSize = Size.Empty;
                    if (m_HeaderMarkup == null)
                    {
                        info.Bounds = headerRect;
                        eTextFormat format = eTextFormat.Default | eTextFormat.WordBreak;
                        if (this.RightToLeft == RightToLeft.Yes) format |= eTextFormat.RightToLeft;
                        ElementStyleDisplay.PaintText(info, m_HeaderText, headerFont, true, format);
                        headerSize = TextDrawing.MeasureString(g, m_HeaderText, headerFont, headerRect.Width, format);
                    }
                    else if(headerRect.Width>0 && headerRect.Height>0)
                    {
                        TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, info.Style.TextColor,
                            (this.RightToLeft == RightToLeft.Yes), headerRect, true);
                        m_HeaderMarkup.Arrange(headerRect, d);
                        m_HeaderMarkup.Render(d);
                        headerSize = m_HeaderMarkup.Bounds.Size;
                    }
                    headerSize.Width += headerPadding.Horizontal;
                    headerSize.Height += headerPadding.Vertical;
                    r.Y += headerSize.Height;
                    r.Height -= headerSize.Height;
                }

                if (m_FooterText != "" && FooterVisible && r.Width>0 && r.Height>0 && (m_ShowTooltipDescription || m_HeaderText==""))
                {
                    Size footerSize = Size.Empty;
                    eTextFormat format = eTextFormat.Default | eTextFormat.WordBreak;
                    if (m_FooterMarkup == null)
                        footerSize = TextDrawing.MeasureString(g, m_FooterText, headerFont, r.Width - footerPadding.Horizontal, format);
                    else
                        footerSize = m_FooterMarkup.Bounds.Size;

                    if (m_FooterImage != null && m_FooterImage.Height > footerSize.Height)
                        footerSize.Height = m_FooterImage.Height;

                    Rectangle footerRect = new Rectangle(r.X+footerPadding.Left,
                        r.Bottom-footerSize.Height-footerPadding.Bottom,
                        r.Width - footerPadding.Horizontal, footerSize.Height);
                    if (this.FooterSeparator)
                    {
                        using (Pen pen = new Pen(style.BorderColor, 1))
                            g.DrawLine(pen, 0, footerRect.Y - footerPadding.Top - 1, this.ClientRectangle.Right, footerRect.Y - footerPadding.Top - 1);
                    }
                    if (m_FooterImage != null)
                    {
                        g.DrawImage(m_FooterImage, new Rectangle(footerRect.X, footerRect.Y + (footerRect.Height - m_FooterImage.Height) / 2, m_FooterImage.Width, m_FooterImage.Height));
                        footerRect.X += (m_FooterImage.Width + m_FooterImageSpacing);
                        footerRect.Width -= (m_FooterImage.Width + m_FooterImageSpacing);
                    }
                    if (footerRect.Width > 0 && footerRect.Height > 0)
                    {
                        if (m_FooterMarkup == null)
                        {
                            info.Bounds = footerRect;

                            format |= eTextFormat.VerticalCenter;
                            if (this.RightToLeft == RightToLeft.Yes) format |= eTextFormat.RightToLeft;
                            ElementStyleDisplay.PaintText(info, m_FooterText, headerFont, true, format);
                        }
                        else
                        {
                            TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, info.Style.TextColor,
                            (this.RightToLeft == RightToLeft.Yes), footerRect, true);
                            m_FooterMarkup.Arrange(footerRect, d);
                            m_FooterMarkup.Render(d);
                            footerSize = m_FooterMarkup.Bounds.Size;
                        }
                    }

                    footerSize.Width += footerPadding.Horizontal;
                    footerSize.Height += footerPadding.Vertical;
                    r.Height -= footerSize.Height;
                }

                if (m_ShowTooltipDescription || m_HeaderText == "")
                {
                    if (m_BodyImage != null)
                    {
                        Rectangle imageRect = new Rectangle(r.X + imagePadding.Left, r.Y + imagePadding.Top, m_BodyImage.Width, m_BodyImage.Height);
                        g.DrawImage(m_BodyImage, imageRect);
                        r.X += (imagePadding.Horizontal + m_BodyImage.Width);
                        r.Width -= (imagePadding.Horizontal + m_BodyImage.Width);
                    }

                    if (this.Text != "" && r.Width > 0 && r.Height > 0)
                    {
                        Rectangle textRect = new Rectangle(r.X + textPadding.Left, r.Y + textPadding.Top, r.Width - textPadding.Horizontal, r.Height - textPadding.Vertical);
                        if (m_BodyMarkup == null)
                        {
                            info.Bounds = textRect;
                            if (textRect.Width > 0 && textRect.Height > 0)
                            {
                                eTextFormat format = info.Style.TextFormat;
                                if (this.RightToLeft == RightToLeft.Yes) format |= eTextFormat.RightToLeft;
                                ElementStyleDisplay.PaintText(info, this.Text, font, false, format);
                            }
                        }
                        else if (textRect.Width > 0 && textRect.Height > 0)
                        {
                            TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, info.Style.TextColor,
                                (this.RightToLeft == RightToLeft.Yes), textRect, true);
                            m_BodyMarkup.Arrange(textRect, d);
                            m_BodyMarkup.Render(d);
                        }
                    }
                }
            }
            finally
            {
                headerFont.Dispose();
            }

        }
示例#17
0
        /// <summary>
        /// Calculates the tooltip height based on the specified width.
        /// </summary>
        /// <param name="width">Tooltip width</param>
        /// <returns>Size of the tooltip based on specified width.</returns>
        public Size GetFixedWidthSize(int width)
        {
            Padding headerPadding = GetHeaderPadding();
            Padding footerPadding = GetFooterPadding();
            Padding textPadding = GetTextPadding();
            Padding imagePadding = GetImagePadding();

            Size size = Size.Empty;
            int innerWidth = width - ElementStyleLayout.HorizontalStyleWhiteSpace(this.Style);
            if (innerWidth <= 6) innerWidth = 16;
            Font font = this.Font;
            if (this.Style.Font != null)
                font = this.Style.Font;

            Font headerFont = new Font(font, (m_ShowTooltipDescription || m_HeaderText == "") ? FontStyle.Bold : FontStyle.Regular);
            Graphics g = this.CreateGraphics();

            if (this.AntiAlias)
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
            }

            try
            {
                if (m_HeaderText != "" && HeaderVisible)
                {
                    Size headerSize = Size.Empty;
                    int w = innerWidth - headerPadding.Horizontal;
                    if (w <= 1) w = 2;

                    if (m_HeaderMarkup == null)
                    {
                        headerSize = TextDrawing.MeasureString(g, m_HeaderText, headerFont, w, eTextFormat.Default | eTextFormat.WordBreak);
                    }
                    else
                    {
                        TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, Color.Black, (this.RightToLeft == RightToLeft.Yes));
                        m_HeaderMarkup.Measure(new Size(w, 1), d);
                        headerSize = m_HeaderMarkup.Bounds.Size;
                        m_HeaderMarkup.Arrange(new Rectangle(Point.Empty, headerSize), d);
                        headerSize = m_HeaderMarkup.Bounds.Size;
                    }
                    //headerSize.Width += 2;
                    headerSize.Height += 2;
                    //headerSize.Width += headerPadding.Horizontal;
                    headerSize.Height += headerPadding.Vertical;
                    //if (headerSize.Width > size.Width)
                    //    size.Width = headerSize.Width;
                    size.Height += headerSize.Height;
                }

                if (m_FooterText != "" && FooterVisible && (m_ShowTooltipDescription || m_HeaderText == ""))
                {
                    Size footerSize = Size.Empty;
                    int w = innerWidth - footerPadding.Horizontal;
                    if (m_FooterImage != null)
                        w-= (m_FooterImage.Width + m_FooterImageSpacing);
                    if (w <= 1) w = 2;

                    if (m_FooterMarkup == null)
                    {
                        footerSize = TextDrawing.MeasureString(g, m_FooterText, headerFont, w, eTextFormat.Default | eTextFormat.WordBreak);
                    }
                    else
                    {
                        TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, Color.Black, (this.RightToLeft == RightToLeft.Yes));
                        m_FooterMarkup.Measure(new Size(w, 1), d);
                        footerSize = m_FooterMarkup.Bounds.Size;
                        m_FooterMarkup.Arrange(new Rectangle(Point.Empty, footerSize), d);
                        footerSize = m_FooterMarkup.Bounds.Size;
                    }
                    //footerSize.Width += 2;
                    footerSize.Height += 2;
                    if (m_FooterImage != null)
                    {
                        //footerSize.Width += (m_FooterImage.Width + m_FooterImageSpacing);
                        if (m_FooterImage.Height > footerSize.Height)
                            footerSize.Height = m_FooterImage.Height;
                    }
                    //footerSize.Width += footerPadding.Horizontal;
                    footerSize.Height += footerPadding.Vertical;
                    //if (footerSize.Width > size.Width)
                    //    size.Width = footerSize.Width;
                    size.Height += footerSize.Height;
                }

                if (m_ShowTooltipDescription || m_HeaderText == "")
                {
                    if (this.Text != "")
                    {
                        int textArea = innerWidth - textPadding.Horizontal;
                        if (m_BodyImage != null)
                            textArea -= (m_BodyImage.Width + imagePadding.Horizontal);

                        if (textArea <= 1)
                            textArea = 2;

                        Size textSize = Size.Empty;

                        if (m_BodyMarkup == null)
                        {
                            textSize = TextDrawing.MeasureString(g, this.Text, font, textArea, this.Style.TextFormat);
                        }
                        else
                        {
                            TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, Color.Black, (this.RightToLeft == RightToLeft.Yes));
                            m_BodyMarkup.Measure(new Size(textArea, 1), d);
                            textSize = m_BodyMarkup.Bounds.Size;

                            if (textSize.Height > textSize.Width * 1.75)
                                textArea = (int)(textSize.Height * .75);

                            m_BodyMarkup.Arrange(new Rectangle(Point.Empty, new Size(textArea, 1)), d);
                            textSize = m_BodyMarkup.Bounds.Size;
                        }

                        //textSize.Width += textPadding.Horizontal;
                        textSize.Height += textPadding.Vertical;

                        if (m_BodyImage != null)
                        {
                            //textSize.Width += (m_BodyImage.Width + imagePadding.Horizontal);
                            if (m_BodyImage.Height + imagePadding.Vertical > textSize.Height)
                                textSize.Height = (m_BodyImage.Height + imagePadding.Vertical);
                        }

                        //if (textSize.Width > size.Width)
                        //    size.Width = textSize.Width;
                        size.Height += textSize.Height;
                    }
                    else
                    {
                        if (m_BodyImage != null)
                        {
                            //if (m_BodyImage.Width + imagePadding.Horizontal > size.Width)
                            //    size.Width = (m_BodyImage.Width + imagePadding.Horizontal);
                            size.Height += (m_BodyImage.Height + imagePadding.Vertical);
                        }
                    }
                }
            }
            finally
            {
                g.Dispose();
                headerFont.Dispose();
            }

            size.Width = width;
            size.Height += ElementStyleLayout.VerticalStyleWhiteSpace(this.Style);

            return size;
        }
示例#18
0
        public override void Paint(ItemPaintArgs pa)
        {
            if (this.SuspendLayout || !IsRendered)
                return;
            
            _ItemPaintArgs = pa;
            System.Drawing.Graphics g = pa.Graphics;

            CompositeImage image = null;
            Size imageSize = Size.Empty;

            bool isSymbolImage = false;
            if (string.IsNullOrEmpty(this.Symbol))
            {
                image = this.GetImage();
                if (image != null)
                    imageSize = image.Size;
            }
            else
            {
                isSymbolImage = true;
                Font symFont = Symbols.GetFontAwesome(this.SymbolSize);
                imageSize = TextDrawing.MeasureString(g, this.Symbol, symFont);
                int descent = (int)Math.Ceiling((symFont.FontFamily.GetCellDescent(symFont.Style) *
                    symFont.Size / symFont.FontFamily.GetEmHeight(symFont.Style)));
                imageSize.Height -= descent;
            }

            Rectangle thisRect = this.DisplayRectangle;
            Rectangle rClip = Rectangle.Empty;
            System.Windows.Forms.Border3DSide borderside;
            if (m_DividerStyle)
            {
                borderside = System.Windows.Forms.Border3DSide.Top;
            }
            else
            {
                if (m_BorderSide == eBorderSide.All)
                    borderside = (System.Windows.Forms.Border3DSide.Left |
                    System.Windows.Forms.Border3DSide.Right | System.Windows.Forms.Border3DSide.Top |
                    System.Windows.Forms.Border3DSide.Bottom);
                else
                    borderside = (((m_BorderSide & eBorderSide.Left) != 0) ? System.Windows.Forms.Border3DSide.Left : 0) |
                    (((m_BorderSide & eBorderSide.Right) != 0) ? System.Windows.Forms.Border3DSide.Right : 0) |
                    (((m_BorderSide & eBorderSide.Top) != 0) ? System.Windows.Forms.Border3DSide.Top : 0) |
                    (((m_BorderSide & eBorderSide.Bottom) != 0) ? System.Windows.Forms.Border3DSide.Bottom : 0);
            }

            if (!(pa.ContainerControl is LabelX))
                DisplayHelp.FillRectangle(g, this.DisplayRectangle, m_BackColor, Color.Empty);

            if (m_DividerStyle)
            {
                System.Windows.Forms.Control ctrl = this.ContainerControl as System.Windows.Forms.Control;
                System.Windows.Forms.RightToLeft rtl = System.Windows.Forms.RightToLeft.No;
                if (ctrl != null && ctrl.RightToLeft == System.Windows.Forms.RightToLeft.Yes)
                    rtl = System.Windows.Forms.RightToLeft.Yes;

                Size sz = TextDrawing.MeasureString(g, m_Text, this.GetFont(), m_Rect.Width, this.GetStringFormat());
                sz.Width += 4;
                if (sz.Width > thisRect.Width)
                    sz.Width = thisRect.Width;
                rClip = new Rectangle(thisRect.X, thisRect.Y, (int)sz.Width, (int)sz.Height);
                if (m_TextAlignment == StringAlignment.Center)
                    rClip.Offset((thisRect.Width - (int)sz.Width) / 2, 0);
                else if (m_TextAlignment == StringAlignment.Far && rtl == System.Windows.Forms.RightToLeft.No || m_TextAlignment == StringAlignment.Near && rtl == System.Windows.Forms.RightToLeft.Yes)
                    rClip.Offset(thisRect.Width - rClip.Width, 0);
                if (m_TextLineAlignment == StringAlignment.Center)
                    rClip.Offset(0, (thisRect.Height - rClip.Height) / 2);
                else if (m_TextLineAlignment == StringAlignment.Far && rtl == System.Windows.Forms.RightToLeft.No || m_TextLineAlignment == StringAlignment.Near && rtl == System.Windows.Forms.RightToLeft.Yes)
                    rClip.Offset(0, thisRect.Height - rClip.Height);
            }
            
            switch (m_BorderType)
            {
                case eBorderType.Bump:
                    if (m_DividerStyle)
                    {
                        System.Windows.Forms.ControlPaint.DrawBorder3D(g, m_Rect.X, m_Rect.Y + m_Rect.Height / 2, m_Rect.Width, 2, System.Windows.Forms.Border3DStyle.Bump, borderside);
                    }
                    else
                    {
                        System.Windows.Forms.ControlPaint.DrawBorder3D(g, m_Rect, System.Windows.Forms.Border3DStyle.Bump, borderside);
                        thisRect.Inflate(-2, -2);
                    }
                    break;
                case eBorderType.Etched:
                    if (m_DividerStyle)
                    {
                        System.Windows.Forms.ControlPaint.DrawBorder3D(g, m_Rect.X, m_Rect.Y + m_Rect.Height / 2, m_Rect.Width, 2, System.Windows.Forms.Border3DStyle.Etched, borderside);
                    }
                    else
                    {
                        System.Windows.Forms.ControlPaint.DrawBorder3D(g, m_Rect, System.Windows.Forms.Border3DStyle.Etched, borderside);
                        thisRect.Inflate(-2, -2);
                    }
                    break;
                case eBorderType.Raised:
                case eBorderType.RaisedInner:
                    if (m_DividerStyle)
                    {
                        System.Windows.Forms.ControlPaint.DrawBorder3D(g, m_Rect.X, m_Rect.Y + m_Rect.Height / 2, m_Rect.Width, 2, System.Windows.Forms.Border3DStyle.RaisedInner, borderside);
                    }
                    else
                    {
                        System.Windows.Forms.ControlPaint.DrawBorder3D(g, m_Rect, System.Windows.Forms.Border3DStyle.RaisedInner, borderside);
                        thisRect.Inflate(-2, -2);
                    }
                    break;
                case eBorderType.Sunken:
                    if (m_DividerStyle)
                    {
                        System.Windows.Forms.ControlPaint.DrawBorder3D(g, m_Rect.X, m_Rect.Y + m_Rect.Height / 2, m_Rect.Width, 2, System.Windows.Forms.Border3DStyle.SunkenOuter, borderside);
                    }
                    else
                    {
                        System.Windows.Forms.ControlPaint.DrawBorder3D(g, m_Rect, System.Windows.Forms.Border3DStyle.SunkenOuter, borderside);
                        thisRect.Inflate(-2, -2);
                    }
                    break;
                case eBorderType.SingleLine:
                    if (m_DividerStyle)
                    {
                        g.DrawLine(new Pen(GetSingleLineColor(), 1), m_Rect.X, m_Rect.Y + m_Rect.Height / 2, m_Rect.Right, m_Rect.Y + m_Rect.Height / 2);
                    }
                    else
                    {
                        BarFunctions.DrawBorder(g, eBorderType.SingleLine, m_Rect, GetSingleLineColor(), m_BorderSide, DashStyle.Solid, 1);
                        thisRect.Inflate(-1, -1);
                    }
                    break;
                case eBorderType.DoubleLine:
                    {
                        BarFunctions.DrawBorder(g, eBorderType.DoubleLine, m_Rect, GetSingleLineColor());
                        thisRect.Inflate(-2, -2);
                        break;
                    }
                default:
                    break;
            }

            if (m_DividerStyle)
                g.FillRectangle(new SolidBrush(m_BackColor), rClip);

            eOrientation orientation = this.Orientation;
            if (_TextOrientation == eOrientation.Vertical) orientation = _TextOrientation;

            if (orientation == eOrientation.Horizontal)
                thisRect.X += m_PaddingLeft;
            else
                thisRect.Y += m_PaddingLeft;

            if (orientation == eOrientation.Horizontal)
                thisRect.Width -= (m_PaddingLeft + m_PaddingRight);
            else
                thisRect.Width -= (m_PaddingTop + m_PaddingBottom);
            thisRect.Y += m_PaddingTop;
            if (orientation == eOrientation.Horizontal)
                thisRect.Height -= (m_PaddingTop + m_PaddingBottom);
            else
                thisRect.Height -= (m_PaddingLeft + m_PaddingRight);

            Color textColor = GetTextColor(pa);
            Color symbolColor = textColor;
            if (!this.SymbolColor.IsEmpty) symbolColor = this.SymbolColor;

            if (image != null || isSymbolImage)
            {
                switch (m_ImagePosition)
                {
                    case eImagePosition.Left:
                        {
                            if (orientation == eOrientation.Horizontal)
                            {
                                if (isSymbolImage)
                                    TextDrawing.DrawStringLegacy(g, this.Symbol, Symbols.GetFontAwesome(this.SymbolSize), symbolColor, new Rectangle(thisRect.X + ImageTextSpacing, (thisRect.Y + (thisRect.Height - imageSize.Height) / 2),0,0), eTextFormat.Default);
                                else
                                   image.DrawImage(g, new Rectangle(thisRect.X + ImageTextSpacing, (thisRect.Y + (thisRect.Height - imageSize.Height) / 2), imageSize.Width, imageSize.Height));
                                thisRect.X += (imageSize.Width + ImageTextSpacing * 2);
                                thisRect.Width -= (imageSize.Width + ImageTextSpacing * 2);
                            }
                            else
                            {
                                if (isSymbolImage)
                                    TextDrawing.DrawStringLegacy(g, this.Symbol, Symbols.GetFontAwesome(this.SymbolSize), symbolColor, new Rectangle(thisRect.X + (thisRect.Width - imageSize.Height) / 2, thisRect.Y + ImageTextSpacing, 0, 0), eTextFormat.Default);
                                else
                                    image.DrawImage(g, new Rectangle(thisRect.X + (thisRect.Width - imageSize.Height) / 2, thisRect.Y + ImageTextSpacing, imageSize.Width, imageSize.Height));
                                thisRect.Y += (imageSize.Height + ImageTextSpacing * 2);
                                thisRect.Height -= (imageSize.Height + ImageTextSpacing * 2);
                            }
                            break;
                        }
                    case eImagePosition.Right:
                        {
                            if (orientation == eOrientation.Horizontal)
                            {
                                if (isSymbolImage)
                                    TextDrawing.DrawStringLegacy(g, this.Symbol, Symbols.GetFontAwesome(this.SymbolSize), symbolColor, new Rectangle(thisRect.Right - imageSize.Width - ImageTextSpacing, (thisRect.Y + (thisRect.Height - imageSize.Height) / 2), 0, 0), eTextFormat.Default);
                                else
                                    image.DrawImage(g, new Rectangle(thisRect.Right - imageSize.Width - ImageTextSpacing, (thisRect.Y + (thisRect.Height - imageSize.Height) / 2), imageSize.Width, imageSize.Height));
                                thisRect.Width -= (imageSize.Width + ImageTextSpacing * 2);
                            }
                            else
                            {
                                if (isSymbolImage)
                                    TextDrawing.DrawStringLegacy(g, this.Symbol, Symbols.GetFontAwesome(this.SymbolSize), symbolColor, new Rectangle(thisRect.X, thisRect.Bottom - imageSize.Height - ImageTextSpacing, 0, 0), eTextFormat.Default);
                                else
                                    image.DrawImage(g, new Rectangle(thisRect.X, thisRect.Bottom - imageSize.Height - ImageTextSpacing, imageSize.Width, imageSize.Height));
                                thisRect.Height -= (imageSize.Height + ImageTextSpacing * 2);
                            }
                            break;
                        }
                    case eImagePosition.Top:
                        {
                            if (orientation == eOrientation.Horizontal)
                            {
                                if (isSymbolImage)
                                    TextDrawing.DrawStringLegacy(g, this.Symbol, Symbols.GetFontAwesome(this.SymbolSize), symbolColor, new Rectangle(thisRect.X + (thisRect.Width - imageSize.Width) / 2, thisRect.Y, 0, 0), eTextFormat.Default);
                                else
                                    image.DrawImage(g, new Rectangle(thisRect.X + (thisRect.Width - imageSize.Width) / 2, thisRect.Y, imageSize.Width, imageSize.Height));
                                thisRect.Y += (imageSize.Height + ImageTextSpacing);
                                thisRect.Height -= (imageSize.Height + ImageTextSpacing);
                            }
                            else
                            {
                                if (isSymbolImage)
                                    TextDrawing.DrawStringLegacy(g, this.Symbol, Symbols.GetFontAwesome(this.SymbolSize), symbolColor, new Rectangle(thisRect.X, thisRect.Y + (thisRect.Height - imageSize.Height) / 2, 0, 0), eTextFormat.Default);
                                else
                                    image.DrawImage(g, new Rectangle(thisRect.X, thisRect.Y + (thisRect.Height - imageSize.Height) / 2, imageSize.Width, imageSize.Height));
                                thisRect.X += (imageSize.Width + ImageTextSpacing);
                                thisRect.Width -= (imageSize.Width + ImageTextSpacing);
                            }
                            break;
                        }
                    case eImagePosition.Bottom:
                        {
                            if (orientation == eOrientation.Horizontal)
                            {
                                if (isSymbolImage)
                                    TextDrawing.DrawStringLegacy(g, this.Symbol, Symbols.GetFontAwesome(this.SymbolSize), symbolColor, new Rectangle(thisRect.X + (thisRect.Width - imageSize.Width) / 2, thisRect.Bottom - imageSize.Height, 0, 0), eTextFormat.Default);
                                else
                                    image.DrawImage(g, new Rectangle(thisRect.X + (thisRect.Width - imageSize.Width) / 2, thisRect.Bottom - imageSize.Height, imageSize.Width, imageSize.Height));
                                thisRect.Height -= (imageSize.Height + ImageTextSpacing);
                            }
                            else
                            {
                                if (isSymbolImage)
                                    TextDrawing.DrawStringLegacy(g, this.Symbol, Symbols.GetFontAwesome(this.SymbolSize), symbolColor, new Rectangle(thisRect.Right - imageSize.Width, thisRect.Y + (thisRect.Height - imageSize.Height) / 2, 0, 0), eTextFormat.Default);
                                else
                                    image.DrawImage(g, new Rectangle(thisRect.Right - imageSize.Width, thisRect.Y + (thisRect.Height - imageSize.Height) / 2, imageSize.Width, imageSize.Height));
                                thisRect.Width -= (imageSize.Width + ImageTextSpacing);
                            }
                            break;
                        }
                }
            }

            if (thisRect.Height > 0 && thisRect.Width > 0)
            {
                if (orientation == eOrientation.Horizontal)
                {
                    if (m_TextAlignment == StringAlignment.Far) thisRect.Width--;
                    if (this.TextMarkupBody != null)
                    {
                        TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.GetFont(), textColor, pa.RightToLeft);
                        d.HotKeyPrefixVisible = !((GetStringFormat() & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
                        if (m_TextLineAlignment == StringAlignment.Near)
                            this.TextMarkupBody.Bounds = new Rectangle(thisRect.Location, this.TextMarkupBody.Bounds.Size);
                        else if (m_TextLineAlignment == StringAlignment.Center)
                            this.TextMarkupBody.Bounds = new Rectangle(new Point(thisRect.X, thisRect.Y + (thisRect.Height - this.TextMarkupBody.Bounds.Height) / 2), this.TextMarkupBody.Bounds.Size);
                        else if (m_TextLineAlignment == StringAlignment.Far)
                            this.TextMarkupBody.Bounds = new Rectangle(new Point(thisRect.X, thisRect.Bottom - this.TextMarkupBody.Bounds.Height), this.TextMarkupBody.Bounds.Size);
                        Region oldClip = g.Clip;
                        Rectangle clipRect = thisRect;
                        clipRect.Inflate(2, 2);
                        g.SetClip(clipRect, CombineMode.Replace);
                        this.TextMarkupBody.Render(d);
                        if (oldClip != null)
                            g.Clip = oldClip;
                        else
                            g.ResetClip();
                    }
                    else
                    {
                        eTextFormat format = GetStringFormat();
                        if (pa.RightToLeft) format |= eTextFormat.RightToLeft;
#if FRAMEWORK20
                        if (pa.GlassEnabled && this.Parent is CaptionItemContainer && !(this.ContainerControl is Ribbon.QatToolbar))
                        {
                            if (!pa.CachedPaint)
                                Office2007RibbonControlPainter.PaintTextOnGlass(g, m_Text, this.GetFont(), thisRect, TextDrawing.GetTextFormat(format));
                        }
                        else
#endif
                            TextDrawing.DrawString(g, m_Text, this.GetFont(), textColor, thisRect, format);
                    }
                }
                else
                {
                    if(_VerticalTextTopUp)
                        g.RotateTransform(90);
                    else
                        g.RotateTransform(-90);
                    if (this.TextMarkupBody != null)
                    {
                        this.TextMarkupBody.Bounds = (_VerticalTextTopUp ? new Rectangle(thisRect.Top, -thisRect.Right, this.TextMarkupBody.Bounds.Width + 2, this.TextMarkupBody.Bounds.Height) :
                            new Rectangle(-thisRect.Bottom, thisRect.X, thisRect.Height + 1, thisRect.Width + 1));
                        TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.GetFont(), textColor, pa.RightToLeft);
                        d.HotKeyPrefixVisible = !((GetStringFormat() & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
                        this.TextMarkupBody.Render(d);
                    }
                    else
                    {
                        TextDrawing.DrawStringLegacy(g, m_Text, this.GetFont(), textColor, (_VerticalTextTopUp ? new Rectangle(thisRect.Top, -thisRect.Right, thisRect.Height + 1, thisRect.Width + 1) :
                            new Rectangle(-thisRect.Bottom, thisRect.X, thisRect.Height + 1, thisRect.Width + 1)), GetStringFormat());
                    }
                    g.ResetTransform();
                }
            }

            //if(this.DesignMode)
            this.DrawInsertMarker(g);

            if (this.DesignMode && this.Focused)
            {
                Rectangle r = m_Rect;
                r.Width--;
                r.Height--;
                //r.Inflate(-1,-1);
                DesignTime.DrawDesignTimeSelection(g, r, pa.Colors.ItemDesignTimeBorder);
            }

            _ItemPaintArgs = null;
        }
示例#19
0
        private void CreateReflection()
        {
            DisposeReflectionImage();
            if (Text.Length == 0 || this.Width <= 0 || this.Height <= 0 || this.Font == null) return;

            // Create image based on the control content
            Bitmap bmp = null;
            if (_TextMarkup == null)
            {
                using(Graphics g = this.CreateGraphics())
                {
                    if (AntiAlias)
                    {
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
                    }
                    Size s = TextDrawing.MeasureString(g, this.Text, this.Font);
                    bmp = new Bitmap(this.Width, s.Height, PixelFormat.Format32bppArgb);
                    _TextSize = s;
                }
                bmp.MakeTransparent();

                Color transparentColor = Color.Empty;
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    bool disposeStyle = false;
                    ElementStyle style = this.GetBackgroundStyle(out disposeStyle);
                    
                    if (AntiAlias)
                    {
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
                        transparentColor = style.BackColor.IsEmpty ? this.BackColor : style.BackColor;
                        if (transparentColor.IsEmpty || transparentColor == Color.Transparent) transparentColor = Color.WhiteSmoke;
                        DisplayHelp.FillRectangle(g, new Rectangle(0, 0, bmp.Width, bmp.Height), transparentColor);
                    }

                    TextDrawing.DrawString(g, this.Text, this.Font, (style.TextColor.IsEmpty ? this.ForeColor : style.TextColor),
                        new Rectangle(0, 0, bmp.Width, bmp.Height), GetTextFormat(style));

                    if (disposeStyle) style.Dispose();
                }
                if (!transparentColor.IsEmpty)
                    bmp.MakeTransparent(transparentColor);
            }
            else
            {
                ResizeMarkup();
                if (_TextMarkup.Bounds.Height > 0)
                {
                    bmp = new Bitmap(this.Width, _TextMarkup.Bounds.Height, PixelFormat.Format32bppArgb);
                    Color transparentColor = Color.Empty;
                    using (Graphics g = Graphics.FromImage(bmp))
                    {
                        bool disposeStyle = false;
                        ElementStyle style = this.GetBackgroundStyle(out disposeStyle);

                        if (AntiAlias)
                        {
                            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                            g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
                            transparentColor = style.BackColor.IsEmpty ? this.BackColor : style.BackColor;
                            if (transparentColor.IsEmpty || transparentColor == Color.Transparent) transparentColor = Color.WhiteSmoke;
                            DisplayHelp.FillRectangle(g, new Rectangle(0, 0, bmp.Width, bmp.Height), transparentColor);
                        }
                        if (_TextMarkup.Bounds.Top > 0)
                            g.TranslateTransform(0, -(_TextMarkup.Bounds.Top - GetContentRectangle().Y));
                        TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, (style.TextColor.IsEmpty ? this.ForeColor : style.TextColor),
                        (this.RightToLeft == RightToLeft.Yes), Rectangle.Empty, true);
                        if (!this.Enabled)
                        {
                            d.IgnoreFormattingColors = true;
                            d.CurrentForeColor = SystemColors.ControlDark;
                        }
                        _TextMarkup.Render(d);

                        if (disposeStyle) style.Dispose();
                    }
                    if (!transparentColor.IsEmpty)
                        bmp.MakeTransparent(transparentColor);
                }
            }

            if (bmp != null)
            {
                _ReflectionBitmap = ImageHelper.CreateReflectionImage(bmp);
                bmp.Dispose();
            }
        }
        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;
                    }
                }
            }
        }
示例#21
0
			public void LayoutSingleCell(LayoutCellInfo info)
			{
				Size textSize=Size.Empty;
				Font font=info.Font;
				int height=0;
				if(info.LayoutStyle.Font!=null)
					font=info.LayoutStyle.Font;

				info.ContextCell.OnLayoutCell();

				if(info.ContextCell.HostedControl!=null)
				{
					Size controlSize=info.ContextCell.HostedControl.Size;
					if(!info.ContextCell.HostedControlSize.IsEmpty)
						controlSize = info.ContextCell.HostedControlSize;
					if(info.CellWidth==0)
						textSize=new Size(controlSize.Width,controlSize.Height);
					else
					{
						int availTextWidth=info.CellWidth-
						                   ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle);
						textSize=new Size(availTextWidth,controlSize.Height);
					}
				}
				else
				{
					// Calculate Text Width and Height
					if(info.CellWidth==0)
					{
						if (info.ContextCell.TextMarkupBody == null)
						{
							string text=info.ContextCell.Text;
							if(text!="")
							{
								if(info.LayoutStyle.WordWrap && info.LayoutStyle.MaximumWidth>0)
									textSize=TextDrawing.MeasureString(info.Graphics, text, font, info.LayoutStyle.MaximumWidth);
								else if(info.ContextCell.Parent!=null && info.ContextCell.Parent.Style!=null && info.ContextCell.Parent.Style.WordWrap && info.ContextCell.Parent.Style.MaximumWidth>0)
									textSize=TextDrawing.MeasureString(info.Graphics, text, font, info.ContextCell.Parent.Style.MaximumWidth);
								else
									textSize=TextDrawing.MeasureString(info.Graphics, text, font);
							}
						}
						else
						{
							Size availSize = new Size(1600, 1);
							if(info.LayoutStyle.WordWrap && info.LayoutStyle.MaximumWidth>0)
								availSize.Width = info.LayoutStyle.MaximumWidth;
							else if(info.ContextCell.Parent!=null && info.ContextCell.Parent.Style!=null && info.ContextCell.Parent.Style.WordWrap && info.ContextCell.Parent.Style.MaximumWidth>0)
								availSize.Width = info.ContextCell.Parent.Style.MaximumWidth;

							TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(info.Graphics, font, Color.Empty, false);
							info.ContextCell.TextMarkupBody.Measure(availSize, d);
							availSize = info.ContextCell.TextMarkupBody.Bounds.Size;
							d.RightToLeft = !info.LeftToRight;
							info.ContextCell.TextMarkupBody.Arrange(new Rectangle(0, 0, availSize.Width, availSize.Height), d);

							textSize = info.ContextCell.TextMarkupBody.Bounds.Size;
						}
					}
					else
					{
						int availTextWidth=info.CellWidth-
						                   ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle);

						availTextWidth-=info.ContextCell.Images.LargestImageSize.Width;
						if(info.ContextCell.CheckBoxVisible)
							availTextWidth-=CheckBoxSize.Width;
						int cellHeight=font.Height;

						if(info.LayoutStyle.WordWrap)
						{
							cellHeight=info.LayoutStyle.MaximumHeight-info.LayoutStyle.MarginTop-
							           info.LayoutStyle.MarginBottom-info.LayoutStyle.PaddingTop-info.LayoutStyle.PaddingBottom;
							
							if (info.ContextCell.TextMarkupBody == null)
							{
								if(availTextWidth>0)
								{
									if(cellHeight>0)
										textSize=TextDrawing.MeasureString(info.Graphics, info.ContextCell.Text,font,new Size(availTextWidth,cellHeight),info.LayoutStyle.TextFormat);
									else
										textSize=TextDrawing.MeasureString(info.Graphics, info.ContextCell.Text, font, availTextWidth, info.LayoutStyle.TextFormat);
								}
							}
							else
							{
								Size availSize = new Size(availTextWidth, 1);
								TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(info.Graphics, font, Color.Empty, false);
								info.ContextCell.TextMarkupBody.Measure(availSize, d);
								availSize = info.ContextCell.TextMarkupBody.Bounds.Size;
								availSize.Width = availTextWidth;
								d.RightToLeft = !info.LeftToRight;
								info.ContextCell.TextMarkupBody.Arrange(new Rectangle(0, 0, availSize.Width, availSize.Height), d);

								textSize = info.ContextCell.TextMarkupBody.Bounds.Size;
							}
						}
						else
							textSize=new Size(availTextWidth,cellHeight);
					}
				}

				if(info.LayoutStyle.WordWrap)
					info.ContextCell.WordWrap=true;
				else
					info.ContextCell.WordWrap=false;

				height=(int)Math.Ceiling((double)textSize.Height);
				if(info.VerticalPartAlignment)
				{
					if(info.ContextCell.Images.LargestImageSize.Height>0)
						height+=info.ContextCell.Images.LargestImageSize.Height;
					if(info.ContextCell.CheckBoxVisible)
						height+=CheckBoxSize.Height;
				}
				else
				{
					if(info.ContextCell.Images.LargestImageSize.Height>height)
						height=info.ContextCell.Images.LargestImageSize.Height;
					if(info.ContextCell.CheckBoxVisible && CheckBoxSize.Height>height)
						height=CheckBoxSize.Height;
				}

				Rectangle r=new Rectangle(info.Left+ElementStyleLayout.LeftWhiteSpace(info.LayoutStyle),
				                          info.Top+ElementStyleLayout.TopWhiteSpace(info.LayoutStyle)
				                          ,info.CellWidth,height);

				if(r.Width==0)
				{
					if(info.VerticalPartAlignment)
					{
						r.Width=(int)Math.Ceiling((double)textSize.Width);
						if(info.ContextCell.Images.LargestImageSize.Width>r.Width)
							r.Width=(info.ContextCell.Images.LargestImageSize.Width+this.ImageTextSpacing);
						if(info.ContextCell.CheckBoxVisible && CheckBoxSize.Width>r.Width)
							r.Width+=(CheckBoxSize.Width+this.ImageTextSpacing);
					}
					else
					{
						r.Width=(int)Math.Ceiling((double)textSize.Width);
						if(info.ContextCell.Images.LargestImageSize.Width>0)
							r.Width+=(info.ContextCell.Images.LargestImageSize.Width+this.ImageTextSpacing);
						if(info.ContextCell.CheckBoxVisible)
							r.Width+=(CheckBoxSize.Width+this.ImageTextSpacing);
					}
				}

				// Now that we have cell bounds store them
				Rectangle rCellBounds=new Rectangle(info.Left,info.Top,info.CellWidth,r.Height+info.LayoutStyle.MarginTop+info.LayoutStyle.MarginBottom+info.LayoutStyle.PaddingTop+info.LayoutStyle.PaddingBottom);
				if(rCellBounds.Width==0)
					rCellBounds.Width=r.Width+ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle);
				info.ContextCell.SetBounds(rCellBounds);

				// Set Position of the image
				if(!info.ContextCell.Images.LargestImageSize.IsEmpty)
				{
					eVerticalAlign va=GetVerticalAlign(info.ContextCell.ImageAlignment);
					eHorizontalAlign ha=GetHorizontalAlign(info.ContextCell.ImageAlignment,info.LeftToRight);
					if(info.VerticalPartAlignment)
						info.ContextCell.SetImageBounds(AlignContentVertical(info.ContextCell.Images.LargestImageSize, ref r, ha, va, this.ImageTextSpacing));
					else
						info.ContextCell.SetImageBounds(AlignContent(info.ContextCell.Images.LargestImageSize, ref r, ha, va, this.ImageTextSpacing));
				}
				else
					info.ContextCell.SetImageBounds(Rectangle.Empty);

				// Set position of the check box
				if(info.ContextCell.CheckBoxVisible)
				{
					eVerticalAlign va=GetVerticalAlign(info.ContextCell.CheckBoxAlignment);
					eHorizontalAlign ha=GetHorizontalAlign(info.ContextCell.CheckBoxAlignment,info.LeftToRight);
					if(info.VerticalPartAlignment)
						info.ContextCell.SetCheckBoxBounds(AlignContentVertical(this.CheckBoxSize, ref r, ha, va, this.ImageTextSpacing));
					else
						info.ContextCell.SetCheckBoxBounds(AlignContent(this.CheckBoxSize, ref r, ha, va, this.ImageTextSpacing));
				}
				else
					info.ContextCell.SetCheckBoxBounds(Rectangle.Empty);
			
				// Set position of the text
				//info.ContextCell.SetTextBounds(Rectangle.Empty);
				if(!textSize.IsEmpty)
					info.ContextCell.TextContentBounds=r;
				else
					info.ContextCell.TextContentBounds=Rectangle.Empty;
            
			}
示例#22
0
        /// <summary>
        /// Measures the markup text
        /// </summary>
        /// <param name="tab"></param>
        /// <param name="g"></param>
        /// <param name="font"></param>
        /// <returns></returns>
        private Size MeasureMarkup(SuperTabItem tab, Graphics g, Font font)
        {
            TextMarkup.MarkupDrawContext d =
                new TextMarkup.MarkupDrawContext(g, font, Color.Black, false);

            Size size = new Size(5000, 5000);

            tab.TextMarkupBody.InvalidateElementsSize();
            tab.TextMarkupBody.Measure(size, d);

            d.RightToLeft = _TabStripItem.IsRightToLeft;

            tab.TextMarkupBody.Arrange(new
                Rectangle(Point.Empty, tab.TextMarkupBody.Bounds.Size), d);

            size = tab.TextMarkupBody.Bounds.Size;

            return (size);
        }
示例#23
0
        protected override void OnPaint(PaintEventArgs e)
        {
            BufferedGraphicsContext context = new BufferedGraphicsContext();

            using (Bitmap canvas = new Bitmap(this.Width, this.Height, e.Graphics))
            {
                Graphics g = Graphics.FromImage(canvas);
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                Color glowColor = GetGlowColor(_GlowColor);
                Rectangle r = this.ClientRectangle;
                Color back = _ToastBackColor;

                r.Inflate(-3, -3);

                if (!glowColor.IsEmpty)
                {
                    for (int i = 0; i < GlowSize; i++)
                    {
                        using (Pen pen = new Pen(glowColor, 5))
                        {
                            pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                            g.DrawRectangle(pen, r);
                        }
                        r.Inflate(-1, -1);
                    }
                }

                r = this.ClientRectangle;
                r.Inflate(-GlowSize, -GlowSize);

                using (Pen pen = new Pen(_ToastBackColor, 5))
                {
                    pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                    r.Inflate(-3, -3);
                    g.DrawRectangle(pen, r);
                }
                DisplayHelp.FillRectangle(g, r, _ToastBackColor);

                r = this.ClientRectangle;
                r.Inflate(-(TextPadding.Width + GlowSize), -(TextPadding.Height + GlowSize));

                if (_Image != null)
                {
                    g.DrawImage(_Image, r.Location);
                    r.X += _Image.Width + TextPadding.Width;
                    r.Width -= _Image.Width + TextPadding.Width;
                }

                if (r.Width > 1)
                {
                    if (_TextMarkup == null)
                    {
                        eTextFormat format = TextFormat;
                        if (this.RightToLeft == RightToLeft.Yes) format |= eTextFormat.RightToLeft;
                        //TextDrawing.DrawString(g, Text, this.Font, this.ForeColor, r, format);
                        TextRenderer.DrawText(g, Text, Font, r, this.ForeColor, _ToastBackColor);
                    }
                    else
                    {
                        TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, this.ForeColor,
                            (this.RightToLeft == RightToLeft.Yes), r, true);
                        _TextMarkup.Arrange(r, d);
                        _TextMarkup.Render(d);
                    }
                }

                g.Dispose();

                if (_Alpha == 255)
                {
                    e.Graphics.DrawImage(canvas, 0, 0);
                }
                else
                {
                    ColorMatrix matrix = new ColorMatrix();
                    matrix.Matrix33 = _Alpha / 255f;
                    using (ImageAttributes imageAtt = new ImageAttributes())
                    {
                        imageAtt.SetColorMatrix(matrix);
                        e.Graphics.DrawImage(canvas, new Rectangle(0, 0, canvas.Width, canvas.Height), 0, 0, canvas.Width, canvas.Height, GraphicsUnit.Pixel, imageAtt);
                    }

                }
            }

            base.OnPaint(e);
        }
示例#24
0
        private void PaintText(ItemPaintArgs p, Rectangle bounds)
        {
            Color textColor = Color.Empty;
            if (!_TextColor.IsEmpty)
                textColor = _TextColor;
            else
                textColor = GetTextColor(p);
            bool rtl = p.RightToLeft;
            Rectangle textRect = bounds;
            if (_BackgroundStyle.TextAlignment == eStyleTextAlignment.Far && !rtl || rtl && _BackgroundStyle.TextAlignment == eStyleTextAlignment.Near)
            {
                textRect.X = textRect.Right - _TextSize.Width;
                textRect.Width = _TextSize.Width;
            }
            else
                textRect.Width = _TextSize.Width;
            Graphics g = p.Graphics;
            Font font = p.Font;
            eTextFormat textFormat = _BackgroundStyle.TextFormat;

            if (_TextVisible && this.Text != "" && !textRect.IsEmpty && !textColor.IsEmpty)
            {
                if (this.TextMarkupBody != null)
                {
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, textColor, rtl);
                    d.HotKeyPrefixVisible = !((textFormat & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
                    if ((textFormat & eTextFormat.VerticalCenter) == eTextFormat.VerticalCenter)
                        textRect.Y = this.TopInternal + (this.Bounds.Height - textRect.Height) / 2;
                    else if ((textFormat & eTextFormat.Bottom) == eTextFormat.Bottom)
                        textRect.Y += (this.Bounds.Height - textRect.Height) + 1;

                    this.TextMarkupBody.Bounds = textRect;
                    this.TextMarkupBody.Render(d);
                }
                else
                {
#if FRAMEWORK20
                    if (p.GlassEnabled && this.Parent is CaptionItemContainer && !(p.ContainerControl is QatToolbar))
                    {
                        if (!p.CachedPaint)
                            Office2007RibbonControlPainter.PaintTextOnGlass(g, this.Text, font, textRect, TextDrawing.GetTextFormat(textFormat));
                    }
                    else
#endif
                        TextDrawing.DrawString(g, this.Text, font, textColor, textRect, textFormat);
                }
            }
        }
示例#25
0
        /// <summary>
        /// Draws the chart.
        /// </summary>
        /// <param name="p">Paint arguments</param>
        public override void Paint(ItemPaintArgs p)
        {
            if (_DataPoints != null && _LastDataPointCount != _DataPoints.Count)
                InvalidateChartImage(true);

            if (_ChartImage == null)
                _ChartImage = CreateChartImage();

            Graphics g = p.Graphics;

            Rectangle contentBounds = m_Rect;
            bool onMenu = this.IsOnMenu && !(this.Parent is ItemContainer);
            bool rtl = p.RightToLeft;
            eDotNetBarStyle effectiveStyle = this.EffectiveStyle;
            bool enabled = GetEnabled(p.ContainerControl);

            if (onMenu)
            {
                Size sideBarSize = GetMaxImageSize();
                if (!rtl)
                    contentBounds.X += sideBarSize.Width + 7;
                contentBounds.Width -= sideBarSize.Width + 7;
                DrawMenuSideBar(p, effectiveStyle);
            }

            if (_MouseOverEnabled && enabled && (_IsMouseOver || this.Expanded))
            {
                DrawMouseOverState(p, effectiveStyle);
            }

            if (_BackgroundImage != null)
                BarFunctions.PaintBackgroundImage(g, contentBounds, _BackgroundImage, _BackgroundImagePosition, 255); 

            Point chartLocation = new Point(contentBounds.X + 4 + _Margin.Left, contentBounds.Y + 4 + _Margin.Top);

            if (_TextVisible && !string.IsNullOrEmpty(this.Text))
            {
                Rectangle textRect = contentBounds;

                if (_TextPosition == eMicroChartTextPosition.Left && !rtl || _TextPosition == eMicroChartTextPosition.Right && rtl)
                {
                    textRect.Width = _TextSize.Width;
                    textRect.Y += _TextPadding.Top + _Margin.Top + 1;
                    textRect.X += _Margin.Left + _TextPadding.Left + 1;
                    textRect.Height = Math.Max(_TextSize.Height + 2, _ChartHeight + 6);
                    chartLocation.X = textRect.Right + _TextPadding.Right + TextChartSpacing;
                }
                else if (_TextPosition == eMicroChartTextPosition.Right && !rtl || _TextPosition == eMicroChartTextPosition.Left && rtl)
                {
                    textRect.Width = _TextSize.Width;
                    textRect.Y += _TextPadding.Top + _Margin.Top + 1;
                    textRect.X += _Margin.Left + _TextPadding.Left + _ChartWidth + TextChartSpacing + 1;
                    textRect.Height = Math.Max(_TextSize.Height + 2, _ChartHeight + 6);
                }
                else if (_TextPosition == eMicroChartTextPosition.Top)
                {
                    textRect.Width = _TextSize.Width;
                    textRect.Y += _TextPadding.Top + _Margin.Top + 1;
                    textRect.X += _Margin.Left;
                    textRect.Height = _TextSize.Height;
                    chartLocation.Y = textRect.Bottom + _TextPadding.Bottom + TextChartSpacing;
                    if (_TextSize.Width > _ChartWidth)
                        chartLocation.X += (_TextSize.Width - _ChartWidth) / 2;
                    else
                        textRect.X = chartLocation.X + (_ChartWidth - _TextSize.Width) / 2;
                }
                else if (_TextPosition == eMicroChartTextPosition.Bottom)
                {
                    textRect.Width = _TextSize.Width;
                    textRect.Y += _TextPadding.Top + _Margin.Top + _ChartHeight + TextChartSpacing + 1;
                    textRect.X += _Margin.Left;
                    textRect.Height = _TextSize.Height;
                    if (_TextSize.Width > _ChartWidth)
                        chartLocation.X += (_TextSize.Width - _ChartWidth) / 2;
                    else
                        textRect.X = chartLocation.X + (_ChartWidth - _TextSize.Width) / 2;
                }

                Color textColor = this.TextColor;
                if (textColor.IsEmpty)
                {
                    textColor = LabelItem.GetTextColor(p, this.EffectiveStyle, GetEnabled(), textColor);
                }

                Font textFont = p.Font;
                eTextFormat tf = eTextFormat.Left | eTextFormat.VerticalCenter | eTextFormat.WordBreak;
                if (this.TextMarkupBody != null)
                {
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, textFont, textColor, rtl);
                    d.HotKeyPrefixVisible = !((tf & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
                    if ((tf & eTextFormat.VerticalCenter) == eTextFormat.VerticalCenter)
                        textRect.Y = this.TopInternal + (contentBounds.Height - this.TextMarkupBody.Bounds.Height) / 2;
                    else if ((tf & eTextFormat.Bottom) == eTextFormat.Bottom)
                        textRect.Y += (this.TextMarkupBody.Bounds.Height - textRect.Height) + 1;
                    textRect.Height = this.TextMarkupBody.Bounds.Height;
                    this.TextMarkupBody.Bounds = textRect;
                    this.TextMarkupBody.Render(d);
                }
                else
                {
                    if (p != null && p.GlassEnabled && this.Parent is CaptionItemContainer && !(p.ContainerControl is DevComponents.DotNetBar.Ribbon.QatToolbar))
                    {
                        if (!p.CachedPaint)
                            Office2007RibbonControlPainter.PaintTextOnGlass(g, this.Text, textFont, textRect, TextDrawing.GetTextFormat(tf));
                    }
                    else
                        TextDrawing.DrawString(g, this.Text, textFont, textColor, textRect, tf);
                }
            }

            if (_TransitionImage != null)
            {
                Rectangle chartRect = new Rectangle(chartLocation.X, chartLocation.Y, _ChartWidth, _ChartHeight);
                System.Drawing.Imaging.ColorMatrix matrix1 = new System.Drawing.Imaging.ColorMatrix();
                matrix1[3, 3] = (1 - _TransitionOpacity);
                using (System.Drawing.Imaging.ImageAttributes imageAtt = new System.Drawing.Imaging.ImageAttributes())
                {
                    imageAtt.SetColorMatrix(matrix1);
                    g.DrawImage(_TransitionImage, chartRect, 0, 0, chartRect.Width, chartRect.Height, GraphicsUnit.Pixel, imageAtt);
                }
                matrix1[3, 3] = _TransitionOpacity;
                using (System.Drawing.Imaging.ImageAttributes imageAtt = new System.Drawing.Imaging.ImageAttributes())
                {
                    imageAtt.SetColorMatrix(matrix1);
                    g.DrawImage(_ChartImage, chartRect, 0, 0, chartRect.Width, chartRect.Height, GraphicsUnit.Pixel, imageAtt);
                }
            }
            else
            {
                g.DrawImage(_ChartImage, chartLocation);
            }

            _ChartLocation = chartLocation;

            if (_TrackChartPoints && !_HotPoint.IsEmpty)
            {
                Rectangle hotPointBounds = _HotPoint.HotPointBounds;
                hotPointBounds.Offset(chartLocation);
                using (Pen pen = new Pen(Brushes.DarkGray))
                {
                    g.FillEllipse(Brushes.White, hotPointBounds);
                    g.DrawEllipse(pen, hotPointBounds);
                }
                hotPointBounds.Inflate(-2, -2);
                using (SolidBrush brush = new SolidBrush(_HotPoint.Color))
                    g.FillEllipse(brush, hotPointBounds);
            }

            //g.DrawRectangle(Pens.Yellow, new Rectangle(m_Rect.X, m_Rect.Y, m_Rect.Width - 1, m_Rect.Height - 1));

            if (this.Focused && this.DesignMode)
            {
                Rectangle r = m_Rect;
                r.Inflate(-1, -1);
                DesignTime.DrawDesignTimeSelection(g, r, p.Colors.ItemDesignTimeBorder);
            }

            this.DrawInsertMarker(p.Graphics);
        }
示例#26
0
        private void NCAfterBorderPaint(object sender, CustomNCPaintEventArgs e)
        {
            Graphics g = e.Graphics;

            TextRenderingHint th = g.TextRenderingHint;
            SmoothingMode sm = g.SmoothingMode;
            if (this.AntiAlias)
            {
                g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
                g.SmoothingMode = SmoothingMode.AntiAlias;
            }
            g.ResetClip();
            ElementStyle style = this.Style;

            if (!this.Enabled)
            {
                style = style.Copy();
                style.TextColor = GetColorScheme().ItemDisabledText;
            }

            if (m_DrawTitleBox && !m_TitleArea.IsEmpty)
            {
                DisplayHelp.FillRoundedRectangle(g, m_TitleArea, 2, style.BackColor, style.BackColor2, -90);
                DisplayHelp.DrawRoundedRectangle(g, this.Style.BorderColor, m_TitleArea, 2);
            }

            Rectangle rText = new Rectangle(m_NCPainter.ClientRectangle.X + 4, 1, this.ClientRectangle.Width - 8, m_NCPainter.ClientRectangle.Y - 1);
            if (m_TitleImage != null)
            {
                Size textSize = GetAutoSize(rText.Width);
                if (m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.No || m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.Yes)
                {
                    g.DrawImage(m_TitleImage, rText.X - 1, rText.Y, m_TitleImage.Width, m_TitleImage.Height);
                    rText.X += m_TitleImage.Width;
                    rText.Width -= m_TitleImage.Width;
                }
                else if (m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.No || m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.Yes)
                {
                    g.DrawImage(m_TitleImage, rText.Right - m_TitleImage.Width, rText.Y, m_TitleImage.Width, m_TitleImage.Height);
                    rText.Width -= m_TitleImage.Width;
                }
                else if (m_TitleImagePosition == eTitleImagePosition.Center)
                {
                    g.DrawImage(m_TitleImage, rText.X + (rText.Width - m_TitleImage.Width) / 2, rText.Y, m_TitleImage.Width, m_TitleImage.Height);
                }
                rText.Y = rText.Bottom - textSize.Height - 2;
            }

            // Paint text
            if (this.TextMarkupElement == null)
            {
                ElementStyleDisplayInfo info = new ElementStyleDisplayInfo(style, g, rText);
                info.RightToLeft = (this.RightToLeft == RightToLeft.Yes);
                ElementStyleDisplay.PaintText(info, this.Text, this.Font);
            }
            else
            {
                TextRenderingHint tr = g.TextRenderingHint;
                if (this.AntiAlias)
                    g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
                TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, style.TextColor, (this.RightToLeft == RightToLeft.Yes), Rectangle.Empty, true);
                Rectangle r = this.TextMarkupElement.Bounds;
                if (style.TextAlignment == eStyleTextAlignment.Center)
                    this.TextMarkupElement.Bounds = new Rectangle(this.TextMarkupElement.Bounds.X + (rText.Width - this.TextMarkupElement.Bounds.Width) / 2, this.TextMarkupElement.Bounds.Y,
                        this.TextMarkupElement.Bounds.Width, this.TextMarkupElement.Bounds.Height);
                else if(style.TextAlignment == eStyleTextAlignment.Far && this.RightToLeft == RightToLeft.No || this.RightToLeft == RightToLeft.Yes && style.TextAlignment== eStyleTextAlignment.Near)
                    this.TextMarkupElement.Bounds = new Rectangle(rText.Right - this.TextMarkupElement.Bounds.Width, this.TextMarkupElement.Bounds.Y,
                        this.TextMarkupElement.Bounds.Width, this.TextMarkupElement.Bounds.Height);
                this.TextMarkupElement.Render(d);
                g.TextRenderingHint = tr;
                this.TextMarkupElement.Bounds = r;
            }

            g.TextRenderingHint = th;
            g.SmoothingMode = sm;
        }
示例#27
0
        public override void Paint(SwitchButtonRenderEventArgs e)
        {
            SwitchButtonItem switchButton = e.SwitchButtonItem;
            bool enabled = switchButton.Enabled;
            SwitchButtonColorTable colorTable = enabled ? this.ColorTable.SwitchButton.Default : this.ColorTable.SwitchButton.Disabled;
            if (colorTable == null) colorTable = new SwitchButtonColorTable();

            Rectangle bounds = switchButton.Bounds;
            Graphics g = e.Graphics;

            if (e.ItemPaintArgs != null && e.ItemPaintArgs.ContainerControl is AdvTree.AdvTree)
            {
                if (switchButton.ItemAlignment == eItemAlignment.Far)
                    bounds.X = bounds.Right - switchButton.Margin.Right - switchButton.ButtonWidth;
                else if (switchButton.ItemAlignment == eItemAlignment.Center)
                    bounds.X += (bounds.Width - switchButton.ButtonWidth) / 2;
            }
            else
                bounds.X = bounds.Right - switchButton.Margin.Right - switchButton.ButtonWidth;
            bounds.Width = switchButton.ButtonWidth;
            bounds.Y += switchButton.Margin.Top + (bounds.Height - switchButton.Margin.Vertical - switchButton.ButtonHeight) / 2;
            bounds.Height = switchButton.ButtonHeight;
            switchButton.ButtonBounds = bounds;
            bool rendersOnGlass = (e.ItemPaintArgs != null && e.ItemPaintArgs.GlassEnabled && (switchButton.Parent is CaptionItemContainer && !(e.ItemPaintArgs.ContainerControl is QatToolbar) || (switchButton.Parent is RibbonTabItemContainer && switchButton.EffectiveStyle == eDotNetBarStyle.Office2010)));
            
            if (switchButton.TextVisible && !string.IsNullOrEmpty(switchButton.Text))
            {
                Rectangle textRect = switchButton.Bounds;
                textRect.Width -= switchButton.ButtonWidth + switchButton.Margin.Right;
                textRect.Y += switchButton.TextPadding.Top;
                textRect.Height -= switchButton.TextPadding.Vertical;
                bool rtl = e.RightToLeft;
                Color textColor = (switchButton.TextColor.IsEmpty || !enabled) ? colorTable.TextColor : switchButton.TextColor;
                Font textFont = e.Font;
                eTextFormat tf = eTextFormat.Left | eTextFormat.VerticalCenter;
                if (switchButton.TextMarkupBody != null)
                {
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, textFont, textColor, rtl);
                    d.HotKeyPrefixVisible = !((tf & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
                    if ((tf & eTextFormat.VerticalCenter) == eTextFormat.VerticalCenter)
                        textRect.Y = switchButton.TopInternal + (switchButton.Bounds.Height - switchButton.TextMarkupBody.Bounds.Height) / 2;
                    else if ((tf & eTextFormat.Bottom) == eTextFormat.Bottom)
                        textRect.Y += (switchButton.TextMarkupBody.Bounds.Height - textRect.Height) + 1;
                    textRect.Height = switchButton.TextMarkupBody.Bounds.Height;
                    switchButton.TextMarkupBody.Bounds = textRect;
                    switchButton.TextMarkupBody.Render(d);
                }
                else
                {
#if FRAMEWORK20
                    if (rendersOnGlass)
                    {
                        if (!e.ItemPaintArgs.CachedPaint)
                            Office2007RibbonControlPainter.PaintTextOnGlass(g, switchButton.Text, textFont, textRect, TextDrawing.GetTextFormat(tf));
                    }
                    else
#endif
                        TextDrawing.DrawString(g, switchButton.Text, textFont, textColor, textRect, tf);
                }
            }


            bool switchState = switchButton.Value;
            string offText = switchButton.OffText;
            string onText = switchButton.OnText;
            Font font = (switchButton.SwitchFont == null) ? new Font(e.Font, FontStyle.Bold) : switchButton.SwitchFont;
            Color textOffColor = (switchButton.OffTextColor.IsEmpty || !enabled) ? colorTable.OffTextColor : switchButton.OffTextColor;
            Color textOnColor = (switchButton.OnTextColor.IsEmpty || !enabled) ? colorTable.OnTextColor : switchButton.OnTextColor;

            int switchWidth = switchButton.SwitchWidth;
            int switchX = Math.Min(bounds.X + switchButton.SwitchOffset, bounds.Right);
            if (switchState)
            {
                switchX = Math.Max(bounds.Right - switchWidth - switchButton.SwitchOffset, bounds.X);
            }

            Color borderColor = (switchButton.BorderColor.IsEmpty || !enabled) ? colorTable.BorderColor : switchButton.BorderColor;
            Color offBackgroundColor = (switchButton.OffBackColor.IsEmpty || !enabled) ? colorTable.OffBackColor : switchButton.OffBackColor;
            Color onBackgroundColor = (switchButton.OnBackColor.IsEmpty || !enabled) ? colorTable.OnBackColor : switchButton.OnBackColor;

            // Main control border
            DisplayHelp.DrawRectangle(g, borderColor, bounds);

            // Set clip
            Rectangle innerBoundsClip = bounds;
            innerBoundsClip.Inflate(-2, -2);
            GraphicsPath innerClipPath = new GraphicsPath();
            innerClipPath.AddRectangle(innerBoundsClip);
            Region oldClip = g.Clip;
            g.SetClip(innerClipPath, System.Drawing.Drawing2D.CombineMode.Intersect);
            innerClipPath.Dispose();


            // Draw On Background, it is to the left of the switch
            Rectangle onBounds = new Rectangle(switchX - (bounds.Width - switchWidth), bounds.Y, bounds.Width - switchWidth + 2, bounds.Height);
            switchButton.OnPartBounds = onBounds;
            onBounds.Inflate(-2, -2);
            DisplayHelp.FillRectangle(g, onBounds, onBackgroundColor);
            if (!string.IsNullOrEmpty(onText))
            {
                // Draw On Text
                if (rendersOnGlass && BarUtilities.UseTextRenderer)
                    TextDrawing.DrawStringLegacy(g, onText, font, textOnColor, onBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);
                else
                    TextDrawing.DrawString(g, onText, font, textOnColor, onBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter | eTextFormat.NoClipping);
            }
           
            // Draw Off Background, it is on the right of the switch 
            Rectangle offBounds = new Rectangle(switchX + switchWidth - 2, bounds.Y, bounds.Width - switchWidth + 2, bounds.Height);
            switchButton.OffPartBounds = offBounds;
            offBounds.Inflate(-2, -2);
            DisplayHelp.FillRectangle(g, offBounds, offBackgroundColor);

            if (!string.IsNullOrEmpty(offText))
            {
                // Draw Off Text
                if (rendersOnGlass && BarUtilities.UseTextRenderer)
                    TextDrawing.DrawStringLegacy(g, offText, font, textOffColor, offBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);
                else
                    TextDrawing.DrawString(g, offText, font, textOffColor, offBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter | eTextFormat.NoClipping);
            }
            
            // Restore old clip
            g.Clip = oldClip;
            oldClip.Dispose();

            // Draw Switch on top
            Rectangle switchBounds = new Rectangle(switchX, bounds.Y, switchWidth, bounds.Height);
            switchButton.SwitchBounds = switchBounds;
            Color switchBorderColor = (switchButton.SwitchBorderColor.IsEmpty || !enabled) ? colorTable.SwitchBorderColor : switchButton.SwitchBorderColor;
            Color switchFillColor = (switchButton.SwitchBackColor.IsEmpty || !enabled) ? colorTable.SwitchBackColor : switchButton.SwitchBackColor;

            DisplayHelp.FillRectangle(g, switchBounds, switchFillColor);
            if(!switchBorderColor.IsEmpty)
                DisplayHelp.DrawRectangle(g, switchBorderColor, switchBounds);
            
            if (switchButton.IsReadOnly && switchButton.ShowReadOnlyMarker)
            {
                Color markerColor = switchButton.ReadOnlyMarkerColor;
                Rectangle marker = new Rectangle(switchBounds.X + (switchBounds.Width - 7) / 2, switchBounds.Y + (switchBounds.Height - 10) / 2, 7, 10);
                SmoothingMode sm = g.SmoothingMode;
                g.SmoothingMode = SmoothingMode.None;
                using (SolidBrush brush = new SolidBrush(markerColor))
                {
                    g.FillRectangle(brush, new Rectangle(marker.X, marker.Y + 4, marker.Width, marker.Height - 4));
                    g.FillRectangle(Brushes.White, new Rectangle(marker.X + 3, marker.Y + 5, 1, 2));
                }
                using (Pen pen = new Pen(markerColor, 1))
                {
                    g.DrawLine(pen, marker.X + 2, marker.Y + 0, marker.X + 4, marker.Y + 0);
                    g.DrawLine(pen, marker.X + 1, marker.Y + 1, marker.X + 1, marker.Y + 3);
                    g.DrawLine(pen, marker.X + 5, marker.Y + 1, marker.X + 5, marker.Y + 3);
                }
                g.SmoothingMode = sm;
            }
        }
示例#28
0
        private Size GetMarkupSize(int proposedWidth)
        {
            Size size = Size.Empty;
            if (TextMarkupElement != null)
            {
                Rectangle r = new Rectangle(0, 0, proposedWidth, 500);
                r.Inflate(-2, -2);
                Graphics g = this.CreateGraphics();
                TextMarkup.BodyElement markup = TextMarkup.MarkupParser.Parse(this.Text);
                try
                {
                    if (AntiAlias)
                    {
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
                    }
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, SystemColors.Control, (this.RightToLeft == RightToLeft.Yes));
                    markup.Measure(r.Size, d);
                    size = markup.Bounds.Size;
                }
                finally
                {
                    g.Dispose();
                }
            }

            return size;
        }
示例#29
0
		protected override void OnPaint(PaintEventArgs e)
		{
            // Get the Color of ToolTip text
            Color textColor = SystemColors.InfoText;
            Color backColor = SystemColors.Info;
            Color backColor2=Color.Empty;
            Color borderColor = ColorScheme.GetColor("767676");

            if (_ColorDepth == -1)
            {
                _ColorDepth = Screen.FromControl(this).BitsPerPixel;
            }
            if (_ColorDepth < 8)
            {
                backColor = Color.White;
                textColor = Color.Black;
            }
            else
            {
                if (m_Style == eDotNetBarStyle.Metro)
                {
                    DevComponents.DotNetBar.Metro.ColorTables.MetroColorTable metroColors = DevComponents.DotNetBar.Metro.Rendering.MetroRender.GetColorTable();
                    backColor = metroColors.CanvasColor;
                    textColor = metroColors.ForeColor;
                }
                else if (BarFunctions.IsOffice2007Style(m_Style) && this.BackColor == SystemColors.Control)
                {
                    backColor = ColorScheme.GetColor("FFFFFF");
                    backColor2 = ColorScheme.GetColor("E4E4F0");
                    textColor = ColorScheme.GetColor("4C4C4C");
                }
                else
                {
                    textColor = GetToolTipColor();
                    if (this.BackColor != SystemColors.Control)
                        backColor = this.BackColor;
                }
            }

			Graphics g=e.Graphics;
			Rectangle r=this.ClientRectangle;

            if (m_AntiAlias)
            {
                g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            }

            SmoothingMode sm = g.SmoothingMode;
            g.SmoothingMode = SmoothingMode.None;
            if (BarFunctions.IsOffice2007Style(m_Style))
            {
                DisplayHelp.DrawRectangle(g, borderColor, r);
            }
            else
            {
                System.Windows.Forms.ControlPaint.DrawBorder3D(g, r, System.Windows.Forms.Border3DStyle.Raised, System.Windows.Forms.Border3DSide.All);
            }
			
			r.Inflate(-1,-1);
            if (backColor2.IsEmpty)
                DisplayHelp.FillRectangle(g, r, backColor);
            else
                DisplayHelp.FillRectangle(g, r, backColor, backColor2);
			
			r.Offset(1,0);

            g.SmoothingMode = sm;

            if (m_TextMarkup == null)
                TextDrawing.DrawString(g, GetDrawText(), this.Font, textColor, r, GetStringFormat());
            else
            {
                TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, textColor, (this.RightToLeft == RightToLeft.Yes), e.ClipRectangle, true);
                m_TextMarkup.Bounds = new Rectangle(r.Location, m_TextMarkup.Bounds.Size);
                m_TextMarkup.Render(d);
            }
		}
示例#30
0
        /// <summary>
        /// Paints insides of the control.
        /// </summary>
        /// <param name="e">Paint event arguments.</param>
        protected virtual void PaintInnerContent(PaintEventArgs e, ElementStyle style, bool paintText)
        {
            Graphics g = e.Graphics;
            if (m_TextMarkup == null)
                RefreshTextClientRectangle();
            Rectangle r = new Rectangle(0,0,this.Width, this.Height);
            Rectangle rText = m_ClientTextRectangle;
            //rText.Inflate(-1, -1);

            if (!this.Enabled)
                style.TextColor = GetColorScheme().ItemDisabledText;

            ElementStyleDisplayInfo info = new ElementStyleDisplayInfo(style, g, r);
            info.RightToLeft = (this.RightToLeft == RightToLeft.Yes);
            ElementStyleDisplay.Paint(info);
            
            if (paintText)
            {
                if (m_TextMarkup == null)
                {
                    info.Bounds = rText;
                    ElementStyleDisplay.PaintText(info, this.Text, this.Font);
                }
                else
                {
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, style.TextColor, (this.RightToLeft == RightToLeft.Yes), e.ClipRectangle, true);
                    m_TextMarkup.Render(d);
                }
            }

        }