protected override void OnPaint(PaintEventArgs e) { BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle); using (Brush b = new SolidBrush(ColorizedResources.Instance.BorderDarkColor)) g.FillRectangle(b, ClientRectangle); TextFormatFlags tf = TextFormatFlags.VerticalCenter; int width = g.MeasureText(Text, Font).Width; g.DrawText(Text, Font, new Rectangle(20, -1, width, ClientSize.Height), _uiTheme.TextColor, tf); }
public void Paint(BidiGraphics g) { ColorizedResources colRes = ColorizedResources.Instance; if(!ColorizedResources.UseSystemColors) { using (Brush b = new SolidBrush(Color.FromArgb(64, Color.White))) g.FillRectangle(b, Bounds ); using (Pen p = CreateBorderPen()) { g.DrawLine(p, Bounds.Left, Bounds.Top, Bounds.Left, Bounds.Bottom - 1); // left g.DrawLine(p, Bounds.Right, Bounds.Top, Bounds.Right, Bounds.Bottom - 1); // left g.DrawLine(p, Bounds.Left + 1, Bounds.Bottom, Bounds.Right - 1, Bounds.Bottom); } } }
protected override void OnDrawItem(DrawItemEventArgs e) { // screen invalid drawing states if (DesignMode || e.Index == -1) return; // get post-source we are rendering IPostEditorPostSource postSource = (Items[e.Index] as PostSourceItem).PostSource; // determine image and text to use Image postSourceImage; if (e.Index == _draftsIndex) postSourceImage = _showLargeIcons ? _draftsImageLarge : _draftsImage; else if (e.Index == _recentPostsIndex) postSourceImage = _showLargeIcons ? _recentPostsImageLarge : _recentPostsImage; else postSourceImage = _showLargeIcons ? _weblogImageLarge : _weblogImage; // determine state bool selected = (e.State & DrawItemState.Selected) > 0; // calculate colors Color backColor, textColor; if (selected) { if (Focused) { backColor = _theme.backColorSelectedFocused; textColor = _theme.textColorSelectedFocused; } else { backColor = _theme.backColorSelected; textColor = _theme.textColorSelected; } } else { backColor = _theme.backColor; textColor = _theme.textColor; } BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds); // draw background using (SolidBrush solidBrush = new SolidBrush(backColor)) g.FillRectangle(solidBrush, e.Bounds); if (_showLargeIcons) { // center the image within the list box int imageLeft = e.Bounds.Left + ((e.Bounds.Width / 2) - (ScaleX(postSourceImage.Width) / 2)); int imageTop = e.Bounds.Top + ScaleY(LARGE_TOP_INSET); g.DrawImage(false, postSourceImage, new Rectangle(imageLeft, imageTop, ScaleX(postSourceImage.Width), ScaleY(postSourceImage.Height))); // setup string format TextFormatFlags stringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis | TextFormatFlags.HorizontalCenter; // calculate standard text drawing metrics int leftMargin = ScaleX(ELEMENT_PADDING); int topMargin = imageTop + ScaleY(postSourceImage.Height) + ScaleY(ELEMENT_PADDING); int fontHeight = g.MeasureText(postSource.Name, e.Font).Height; // caption // calculate layout rectangle Rectangle layoutRectangle = new Rectangle( leftMargin, topMargin, e.Bounds.Width - (2 * ScaleX(ELEMENT_PADDING)), fontHeight * TITLE_LINES); // draw caption g.DrawText(postSource.Name, e.Font, layoutRectangle, textColor, stringFormat); } else { // draw post icon g.DrawImage(false, postSourceImage, new Rectangle(e.Bounds.Left + ScaleX(ELEMENT_PADDING), e.Bounds.Top + ScaleY(SMALL_TOP_INSET), ScaleX(postSourceImage.Width), ScaleY(postSourceImage.Height))); // setup string format TextFormatFlags stringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis; // calculate standard text drawing metrics int leftMargin = ScaleX(ELEMENT_PADDING) + ScaleX(postSourceImage.Width) + ScaleX(ELEMENT_PADDING); int topMargin = e.Bounds.Top + ScaleY(SMALL_TOP_INSET); int fontHeight = g.MeasureText(postSource.Name, e.Font).Height; // caption // calculate layout rectangle Rectangle layoutRectangle = new Rectangle( leftMargin, topMargin, e.Bounds.Width - leftMargin - ScaleX(ELEMENT_PADDING), fontHeight * TITLE_LINES); // draw caption g.DrawText(postSource.Name, e.Font, layoutRectangle, textColor, stringFormat); } // draw focus rectange if necessary e.DrawFocusRectangle(); }
/// <summary> /// Draws a menu item. /// </summary> /// <param name="drawItemState">A DrawItemEventArgs that contains the event data.</param> /// <param name="rect">A DrawItemEventArgs that contains the client rectangle.</param> private void DrawMenuItem(DrawItemState drawItemState, Rectangle rect) { // Create graphics context on the offscreen bitmap and set the bounds for painting. Graphics graphics = Graphics.FromImage(offscreenBitmap); graphics.CompositingMode = CompositingMode.SourceOver; graphics.CompositingQuality = CompositingQuality.HighQuality; BidiGraphics g = new BidiGraphics(graphics, new Rectangle(Point.Empty, offscreenBitmap.Size)); try { Rectangle bounds = new Rectangle(0, 0, offscreenBitmap.Width, offscreenBitmap.Height); // Fill the menu item with the system-defined menu color. g.FillRectangle(SystemBrushes.Menu, bounds); // Fill the bitmap area with the system-defind control color. Rectangle bitmapAreaRectangle = new Rectangle(bounds.X, bounds.Y, STANDARD_BITMAP_AREA_WIDTH, bounds.Height); // Fill the background. /* using (SolidBrush solidBrush = new SolidBrush(ApplicationManager.ApplicationStyle.MenuBitmapAreaColor)) graphics.FillRectangle(solidBrush, bitmapAreaRectangle); */ Color backgroundColor = SystemColors.Menu; // If the item is selected, draw the selection rectangle. if ((drawItemState & DrawItemState.Selected) != 0) { DrawHotlight(g, SystemColors.Highlight, bounds, true); backgroundColor = offscreenBitmap.GetPixel(2, 2); } // Obtain the bitmap to draw. If there is one, draw it centered in the bitmap area. Bitmap bitmap = MenuBitmap(drawItemState); if (bitmap != null) g.DrawImage(false, bitmap, new Point( bounds.X + Utility.CenterMinZero(bitmap.Width, bitmapAreaRectangle.Width), bounds.Y + Utility.CenterMinZero(bitmap.Height, bitmapAreaRectangle.Height))); // Obtain the menu text. If it's not "-", then this is a menu item. Otherwise, it's // a separator menu item. if (MenuText() != "-") { // Calculate the text area rectangle. This area excludes an area at the right // edge of the menu item where the system draws the cascade indicator. It would // have been better if MenuItem let us draw the indicator (we did say "OwnerDraw" // afterall), but this is just how it works. Rectangle textAreaRectangle = new Rectangle(bounds.X + STANDARD_BITMAP_AREA_WIDTH + STANDARD_TEXT_PADDING, bounds.Y, bounds.Width - (STANDARD_BITMAP_AREA_WIDTH + STANDARD_TEXT_PADDING + STANDARD_RIGHT_EDGE_PAD), bounds.Height); // Select the brush to draw the menu text with. Color color; if ((drawItemState & DrawItemState.Disabled) == 0) color = SystemColors.MenuText; else color = SystemColors.GrayText; // Determine the size of the shortcut, if it is being shown. if (!(MenuType == MenuType.Context)) { string shortcut; Size shortcutSize; if (ShowShortcut && Shortcut != Shortcut.None) { shortcut = FormatShortcutString(Shortcut); shortcutSize = MeasureShortcutMenuItemText(graphics, shortcut); } else { shortcut = null; shortcutSize = MeasureShortcutMenuItemText(graphics, FormatShortcutString(Shortcut.CtrlIns)); } // Draw the shortcut. if (shortcut != null) { Rectangle shortcutTextRect = textAreaRectangle; TextFormatFlags textFormatTemp = shortcutStringFormat; //DisplayHelper.FixupGdiPlusLineCentering(graphics, menuFont, shortcut, ref stringFormatTemp, ref shortcutTextRect); // Draw the shortcut text. g.DrawText(shortcut, menuFont, shortcutTextRect, color, backgroundColor, textFormatTemp); } // Reduce the width of the text area rectangle to account for the shortcut and // the padding before it. textAreaRectangle.Width -= shortcutSize.Width + STANDARD_TEXT_PADDING; } // Determine which StringFormat to use when drawing the menu item text. TextFormatFlags textFormat; if ((drawItemState & DrawItemState.NoAccelerator) != 0) textFormat = menuItemTextNoHotKeyStringFormat; else textFormat = menuItemTextHotKeyStringFormat; //DisplayHelper.FixupGdiPlusLineCentering(graphics, menuFont, MenuText(), ref stringFormat, ref textAreaRectangle); // Draw the text. g.DrawText(MenuText(), menuFont, textAreaRectangle, color, backgroundColor, textFormat); } else { // Calculate the separator line rectangle. This area excludes an area at the right // edge of the menu item where the system draws the cascade indicator. It would // have been better if MenuItem let us draw the indicator (we did say "OwnerDraw" // after all), but this is just how it works. Rectangle separatorLineRectangle = new Rectangle(bounds.X + STANDARD_SEPARATOR_PADDING, bounds.Y + Utility.CenterMinZero(1, bounds.Height), bounds.Width - STANDARD_SEPARATOR_PADDING, 1); // Fill the separator line rectangle. g.FillRectangle(SystemBrushes.ControlDark, separatorLineRectangle); } } finally { // We're finished with the double buffered painting. Dispose of the graphics context // and draw the offscreen image. Cache the offscreen bitmap, though. graphics.Dispose(); } }
private static void DrawHotlight(BidiGraphics graphics, Color highlightColor, Rectangle hotlightRectangle, bool drawBackground) { // Fill the menu item with the system-defined menu color so the highlight color // looks right. if (drawBackground) graphics.FillRectangle(SystemBrushes.Menu, hotlightRectangle); // Draw the selection indicator using a 25% opaque version of the highlight color. using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(64, highlightColor))) graphics.FillRectangle(solidBrush, hotlightRectangle); // Draw a rectangle around the selection indicator to frame it in better using a // 50% opaque version of the highlight color (this combines with the selection // indicator to be 75% opaque). using (Pen pen = new Pen(Color.FromArgb(128, highlightColor))) graphics.DrawRectangle( pen, new Rectangle( hotlightRectangle.X, hotlightRectangle.Y, hotlightRectangle.Width - 1, hotlightRectangle.Height - 1)); }
/// <summary> /// Draws a top-level menu item. /// </summary> /// <param name="drawItemState">A DrawItemEventArgs that contains the event data.</param> private void DrawMainMenuItem(DrawItemEventArgs ea) { // record state DrawItemState drawItemState = ea.State; // Create graphics context on the offscreen bitmap and set the bounds for painting. //Graphics graphics = Graphics.FromImage(offscreenBitmap); Graphics graphics = ea.Graphics; BidiGraphics g = new BidiGraphics(graphics, new Size(GetMainMenu().GetForm().Width, 0)); //Rectangle bounds = new Rectangle(0, 0, offscreenBitmap.Width, offscreenBitmap.Height); Rectangle bounds = ea.Bounds; // get reference to colorized resources ColorizedResources cres = ColorizedResources.Instance; // Fill the menu item with the correct color Form containingForm = GetMainMenu().GetForm(); if ((containingForm is IMainMenuBackgroundPainter)) { (containingForm as IMainMenuBackgroundPainter).PaintBackground(g.Graphics, g.TranslateRectangle(ea.Bounds)); } else { g.FillRectangle(SystemBrushes.Control, bounds); } // Draw the hotlight or selection rectangle. if ((drawItemState & DrawItemState.HotLight) != 0 || (drawItemState & DrawItemState.Selected) != 0) { // Cheat some for the first top-level menu item. Provide a bit of "air" at the // left of the "HotLight" rectangle so it doesn't run into the frame. int xOffset = (Index == 0) ? 1 : 0; // Calculate the hotlight rectangle. Rectangle hotlightRectangle = new Rectangle(bounds.X + xOffset, bounds.Y + 1, bounds.Width - xOffset - 1, bounds.Height - 1); DrawHotlight(g, cres.MainMenuHighlightColor, hotlightRectangle, !cres.CustomMainMenuPainting); } // Calculate the text area rectangle. This area excludes an area at the right // edge of the menu item where the system draws the cascade indicator. It would // have been better if MenuItem let us draw the indicator (we did say "OwnerDraw" // after all), but this is just how it works. Rectangle textAreaRectangle = new Rectangle(bounds.X, bounds.Y + 1, bounds.Width, bounds.Height); // Determine which StringFormat to use when drawing the menu item text. TextFormatFlags textFormat; if ((drawItemState & DrawItemState.NoAccelerator) != 0) textFormat = mainMenuItemTextNoHotKeyStringFormat; else textFormat = mainMenuItemTextHotKeyStringFormat; //DisplayHelper.FixupGdiPlusLineCentering(graphics, menuFont, MenuText(), ref stringFormat, ref textAreaRectangle); // Draw the shortcut and the menu text. TextRenderer.DrawText(g.Graphics, MenuText(), menuFont, textAreaRectangle, cres.MainMenuTextColor, textFormat); // We're finished with the double buffered painting. Dispose of the graphics context // and draw the offscreen image. Cache the offscreen bitmap, though. graphics.Dispose(); }
protected override void OnPaint(PaintEventArgs e) { BidiGraphics g = new BidiGraphics(e.Graphics, _controlRectangle); Color backgroundColor = ColorizedResources.Instance.SidebarGradientBottomColor; using (Brush brush = new SolidBrush(backgroundColor)) g.FillRectangle(brush, _controlRectangle); if (!(_image == null && (Text == null || Text == string.Empty))) { // draw the border using (Pen pen = new Pen(ColorizedResources.Instance.BorderLightColor)) { g.DrawLine(pen, _controlRectangle.Left, _controlRectangle.Top, _controlRectangle.Width, _controlRectangle.Top); g.DrawLine(pen, _controlRectangle.Left, _controlRectangle.Bottom, _controlRectangle.Width, _controlRectangle.Bottom); } // draw the image if (_image != null) g.DrawImage(true, _image, new Rectangle(_imageRectangle.Left, _imageRectangle.Top, _image.Width, _image.Height)); // draw the text g.DrawText(Text, ApplicationManager.ApplicationStyle.NormalApplicationFont, new Rectangle(_textRectangle.X, _textRectangle.Y, _textRectangle.Width, _textRectangle.Height), ApplicationManager.ApplicationStyle.PrimaryWorkspaceCommandBarTextColor, _stringFormat); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.ResetClip(); BidiGraphics g = new BidiGraphics(e.Graphics, Bounds, false); using (Brush brush = new SolidBrush(SystemColors.ActiveCaption)) { g.FillRectangle(brush, new Rectangle(0, 0, Width - 1, SystemInformation.ToolWindowCaptionHeight)); } using (Pen borderPen = new Pen(Color.FromArgb(127, 157, 185))) { g.DrawRectangle(borderPen, new Rectangle(0, 0, Width - 1, Height - 1)); g.DrawLine(borderPen, 0, SystemInformation.ToolWindowCaptionHeight, Width - 1, SystemInformation.ToolWindowCaptionHeight); } using (Font boldFont = new Font(Font, FontStyle.Bold)) g.DrawText(Text, boldFont, new Rectangle(4, 2, Width - 2, SystemInformation.ToolWindowCaptionHeight - 1), SystemColors.ActiveCaptionText); }
protected override void OnDrawItem(DrawItemEventArgs e) { // screen invalid drawing states if (DesignMode || e.Index == -1) return; Rectangle area = e.Bounds; e.Graphics.ResetClip(); BidiGraphics g = new BidiGraphics(e.Graphics, area); Image borderImage = null; string borderText = ""; object item = Items[e.Index]; if (item != null) borderText = item.ToString(); if (item is IComboImageItem) { IComboImageItem comboItem = (IComboImageItem)item; borderImage = comboItem.Image; } // determine state bool selected = (e.State & DrawItemState.Selected) > 0; // calculate colors Color backColor = SystemColors.Window; Color textColor = SystemColors.ControlText; // setup standard string format TextFormatFlags ellipsesStringFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis; // draw background using (SolidBrush solidBrush = new SolidBrush(backColor)) g.FillRectangle(solidBrush, area); if (selected && Focused && dropDownShowing) { //draw the focus highlight rectangle Rectangle focusRect = new Rectangle(area.X, area.Y, area.Width - 1, area.Height - 1); using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(50, SystemColors.Highlight))) g.FillRectangle(solidBrush, focusRect); using (Pen focusPen = new Pen(SystemColors.Highlight, 1)) g.DrawRectangle(focusPen, focusRect); } // draw border icon if (borderImage != null) { Rectangle imageRect = new Rectangle(area.Left + HORIZONTAL_INSET, area.Top + TOP_INSET, borderImage.Width, borderImage.Height); g.DrawImage(false, borderImage, imageRect); //g.DrawRectangle(Pens.Blue, e.Bounds); } // calculate standard text drawing metrics int leftMargin = HORIZONTAL_INSET + MAX_IMAGE_WIDTH + HORIZONTAL_INSET; // draw title line // post title int titleWidth = e.Bounds.Width - leftMargin - 1; Rectangle titleRectangle = new Rectangle(area.Left + leftMargin, area.Top, titleWidth, area.Height - 1); //g.DrawRectangle(Pens.Red,titleRectangle); g.DrawText( borderText, e.Font, titleRectangle, textColor, ellipsesStringFormat); // focus rectange if necessary e.DrawFocusRectangle(); }
/// <summary> /// Raises the Paint event. /// </summary> /// <param name="e">A PaintEventArgs that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { BidiGraphics g = new BidiGraphics(e.Graphics, VirtualClientRectangle); // Fill the background. if (TopColor == BottomColor) using (SolidBrush solidBrush = new SolidBrush(TopColor)) g.FillRectangle(solidBrush, VirtualClientRectangle); else using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(VirtualClientRectangle, TopColor, BottomColor, LinearGradientMode.Vertical)) g.FillRectangle(linearGradientBrush, VirtualClientRectangle); // Draw the first line of the top bevel, if we should. if (TopBevelStyle != BevelStyle.None) using (SolidBrush solidBrush = new SolidBrush(TopBevelFirstLineColor)) g.FillRectangle(solidBrush, 0, 0, VirtualWidth, 1); if (TopBevelStyle == BevelStyle.DoubleLine) using (SolidBrush solidBrush = new SolidBrush(TopBevelSecondLineColor)) g.FillRectangle(solidBrush, 0, 1, VirtualWidth, 1); // Draw the first line of the bottom bevel. if (BottomBevelStyle == BevelStyle.DoubleLine) { using (SolidBrush solidBrush = new SolidBrush(BottomBevelFirstLineColor)) g.FillRectangle(solidBrush, 0, VirtualHeight - 2, VirtualWidth, 1); using (SolidBrush solidBrush = new SolidBrush(BottomBevelSecondLineColor)) g.FillRectangle(solidBrush, 0, VirtualHeight - 1, VirtualWidth, 1); } else if (BottomBevelStyle == BevelStyle.SingleLine) { using (SolidBrush solidBrush = new SolidBrush(BottomBevelFirstLineColor)) g.FillRectangle(solidBrush, 0, VirtualHeight - 1, VirtualWidth, 1); } // Call the base class's method so that registered delegates receive the event. base.OnPaint(e); }
protected override void OnDrawItem(DrawItemEventArgs e) { // screen invalid drawing states if (DesignMode || e.Index == -1) return; // get post we are rendering PostInfo postInfo = (Items[e.Index] as PostInfoItem).PostInfo; // determine state bool selected = (e.State & DrawItemState.Selected) > 0; // calculate colors Color backColor, textColor; if (selected) { if (Focused) { backColor = _theme.backColorSelectedFocused; textColor = _theme.textColorSelectedFocused; } else { backColor = _theme.backColorSelected; textColor = _theme.textColorSelected; } } else { backColor = _theme.backColor; textColor = _theme.textColor; } BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds); // setup standard string format TextFormatFlags ellipsesStringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis | TextFormatFlags.NoPrefix; // draw background using (SolidBrush solidBrush = new SolidBrush(backColor)) g.FillRectangle(solidBrush, e.Bounds); // draw top-line if necessary //if ( !selected ) { using (Pen pen = new Pen(_theme.topLineColor)) g.DrawLine(pen, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - ScaleY(1)); } // draw post icon g.DrawImage(false, _blogPostImage, new Rectangle( e.Bounds.Left + ScaleX(HORIZONTAL_INSET), e.Bounds.Top + ScaleY(TITLE_INSET), ScaleX(_blogPostImage.Width), ScaleY(_blogPostImage.Height))); // calculate standard text drawing metrics int leftMargin = ScaleX(HORIZONTAL_INSET) + ScaleX(_blogPostImage.Width) + ScaleX(HORIZONTAL_INSET); int topMargin = e.Bounds.Top + ScaleY(TITLE_INSET); // draw title line // post date string dateText = postInfo.PrettyDateDisplay; Size dateSize = g.MeasureText(dateText, e.Font); Rectangle dateRectangle = new Rectangle( e.Bounds.Right - ScaleX(HORIZONTAL_INSET) - dateSize.Width, topMargin, dateSize.Width, dateSize.Height); g.DrawText(dateText, e.Font, dateRectangle, textColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.NoPrefix); // post title int titleWidth = dateRectangle.Left - leftMargin - ScaleX(DATE_PADDING); string titleString = String.Format(CultureInfo.CurrentCulture, "{0}", postInfo.Title); int fontHeight = g.MeasureText(titleString, e.Font).Height; Rectangle titleRectangle = new Rectangle(leftMargin, topMargin, titleWidth, fontHeight); g.DrawText( titleString, e.Font, titleRectangle, textColor, ellipsesStringFormat); // draw post preview // calculate layout rectangle Rectangle layoutRectangle = new Rectangle( leftMargin, topMargin + fontHeight + ScaleY(PREVIEW_INSET), e.Bounds.Width - leftMargin - ScaleX(HORIZONTAL_INSET), fontHeight * PREVIEW_LINES); // draw post preview string postPreview = postInfo.PlainTextContents; if (PostSource.HasMultipleWeblogs && (postInfo.BlogName != String.Empty)) postPreview = String.Format(CultureInfo.CurrentCulture, "{0} - {1}", postInfo.BlogName, postPreview); g.DrawText( postPreview, e.Font, layoutRectangle, textColor, ellipsesStringFormat); // focus rectange if necessary e.DrawFocusRectangle(); }
protected override void OnPaint(PaintEventArgs e) { BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle); if (m_pressed) { SystemButtonHelper.DrawSystemButtonFacePushed(g, false, ClientRectangle, false); } else if (m_hover) { SystemButtonHelper.DrawSystemButtonFace(g, false, false, ClientRectangle, false); } Rectangle colorRect = new Rectangle(PADDING, PADDING, COLOR_SIZE, COLOR_SIZE); Rectangle dropDownArrowRect = new Rectangle(Width - PADDING - m_dropDownArrow.Width, PADDING, m_dropDownArrow.Width, colorRect.Height); Rectangle textRect = new Rectangle(PADDING + GUTTER_SIZE + colorRect.Width, PADDING, Width - (PADDING + GUTTER_SIZE + colorRect.Width) - (PADDING + GUTTER_SIZE + dropDownArrowRect.Width), colorRect.Height); using (Brush b = new SolidBrush(EffectiveColor)) g.FillRectangle(b, colorRect); using (Pen p = new Pen(SystemColors.Highlight, 1)) g.DrawRectangle(p, colorRect); g.DrawText(Text, Font, textRect, SystemColors.ControlText, ShowKeyboardCues ? TextFormatFlags.Default : TextFormatFlags.NoPrefix); g.DrawImage(false, m_dropDownArrow, RectangleHelper.Center(m_dropDownArrow.Size, dropDownArrowRect, false), 0, 0, m_dropDownArrow.Width, m_dropDownArrow.Height, GraphicsUnit.Pixel); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); BidiGraphics g = new BidiGraphics(e.Graphics, summaryTextRect); //paint the background over the last text paint using (Brush backBrush = new SolidBrush(BackColor)) { g.FillRectangle(backBrush, summaryTextRect); } Color textColor = Color.DarkGray; Size sizeTextSize; if (linkToSizeText != null) sizeTextSize = g.MeasureText(linkToSizeText, Font, summaryTextRect.Size, imageFileSizeFormat); else sizeTextSize = Size.Empty; Size summaryTextSize = g.MeasureText(linkToSummaryText, Font, new Size(summaryTextRect.Size.Width - sizeTextSize.Width - ScaleX(summarySizeSpacing), sizeTextSize.Height), imageFileSummaryFormat); Rectangle summaryTextLayoutRect = new Rectangle(new Point(summaryTextRect.X, summaryTextRect.Y), summaryTextSize); Rectangle sizeTextLayoutRect = new Rectangle(new Point(summaryTextLayoutRect.Right + summarySizeSpacing, summaryTextRect.Y), sizeTextSize); Rectangle imageViewerTextLayoutRect = new Rectangle(summaryTextRect.X, sizeTextLayoutRect.Bottom + ScaleY(3), ClientRectangle.Width, (int)Math.Ceiling(Font.GetHeight(e.Graphics))); g.DrawText(linkToSummaryText, this.Font, summaryTextLayoutRect, textColor, imageFileSummaryFormat); g.DrawText(linkToSizeText, this.Font, sizeTextLayoutRect, textColor, imageFileSummaryFormat); if (linkToImageViewer != "") g.DrawText(linkToImageViewer, this.Font, imageViewerTextLayoutRect, textColor, imageFileSummaryFormat); }
/// <summary> /// Draws the tab. /// </summary> /// <param name="graphics">Graphics context where the tab page border is to be drawn.</param> private void DrawTab(BidiGraphics graphics) { // Obtain the rectangle. Rectangle virtualClientRectangle = VirtualClientRectangle; // Compute the face rectangle. Rectangle faceRectangle = new Rectangle(virtualClientRectangle.X + 1, virtualClientRectangle.Y + 1, virtualClientRectangle.Width - 2, virtualClientRectangle.Height - (tabEntry.IsSelected ? 1 : 2)); // Fill face of the tab. Color topColor, bottomColor; if (tabEntry.IsSelected) { topColor = TabEntry.TabPageControl.ApplicationStyle.ActiveTabTopColor; bottomColor = TabEntry.TabPageControl.ApplicationStyle.ActiveTabBottomColor; } else { topColor = TabEntry.TabPageControl.ApplicationStyle.InactiveTabTopColor; bottomColor = TabEntry.TabPageControl.ApplicationStyle.InactiveTabBottomColor; } if (topColor == bottomColor) using (SolidBrush solidBrush = new SolidBrush(topColor)) graphics.FillRectangle(solidBrush, faceRectangle); else using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(VirtualClientRectangle, topColor, bottomColor, LinearGradientMode.Vertical)) graphics.FillRectangle(linearGradientBrush, faceRectangle); #if THREEDEE // Draw the highlight inside the tab selector. Color highlightColor; if (tabEntry.IsSelected) highlightColor = TabEntry.TabPageControl.ApplicationStyle.ActiveTabHighlightColor; else highlightColor = TabEntry.TabPageControl.ApplicationStyle.InactiveTabHighlightColor; using (SolidBrush solidBrush = new SolidBrush(highlightColor)) { // Draw the top edge. graphics.FillRectangle( solidBrush, faceRectangle.X, faceRectangle.Y, faceRectangle.Width-1, 1); // Draw the left edge. graphics.FillRectangle( solidBrush, faceRectangle.X, faceRectangle.Y+1, 1, faceRectangle.Height-(tabEntry.IsSelected ? 2 : 1)); } // Draw the lowlight inside the tab selector. Color lowlightColor; if (tabEntry.IsSelected) lowlightColor = TabEntry.TabPageControl.ApplicationStyle.ActiveTabLowlightColor; else lowlightColor = TabEntry.TabPageControl.ApplicationStyle.InactiveTabLowlightColor; using (SolidBrush solidBrush = new SolidBrush(lowlightColor)) { // Draw the right edge. graphics.FillRectangle( solidBrush, faceRectangle.Right-1, faceRectangle.Y+1, 1, faceRectangle.Height-(tabEntry.IsSelected ? 2 : 1)); } #endif // Draw the edges of the tab selector. using (SolidBrush solidBrush = new SolidBrush(TabEntry.TabPageControl.ApplicationStyle.BorderColor)) { // Draw the top edge. graphics.FillRectangle(solidBrush, virtualClientRectangle.X + 2, virtualClientRectangle.Y, virtualClientRectangle.Width - 4, 1); // Draw the left edge. graphics.FillRectangle(solidBrush, virtualClientRectangle.X, virtualClientRectangle.Y + 2, 1, virtualClientRectangle.Height - (tabEntry.IsSelected ? 1 : 2)); // Draw the right edge. graphics.FillRectangle(solidBrush, virtualClientRectangle.Right - 1, virtualClientRectangle.Y + 2, 1, virtualClientRectangle.Height - (tabEntry.IsSelected ? 1 : 2)); // Draw the corners. graphics.FillRectangle(solidBrush, virtualClientRectangle.X + 1, virtualClientRectangle.Y + 1, 1, 1); graphics.FillRectangle(solidBrush, virtualClientRectangle.Right - 2, virtualClientRectangle.Y + 1, 1, 1); } }
protected override void OnDrawItem(DrawItemEventArgs e) { // screen invalid drawing states if (DesignMode || e.Index == -1) return; // get item text and image string itemText = Items[e.Index].ToString(); IComboItem comboItem = (IComboItem)Items[e.Index]; Image itemImage = comboItem.Image; // determine state bool selected = (e.State & DrawItemState.Selected) > 0; // calculate colors Color backColor, textColor; if (selected && Focused) { textColor = SystemColors.ControlText; backColor = Color.FromArgb(50, SystemColors.Highlight); } else { backColor = SystemColors.Window; textColor = SystemColors.ControlText; } Rectangle area = e.Bounds; //overlap issue in RTL builds in the selected box area ONLY if (area.X == 21) { area = ClientRectangle; } BidiGraphics g = new BidiGraphics(e.Graphics, area); // draw background (always paint white over it first) g.FillRectangle(Brushes.White, area); using (SolidBrush solidBrush = new SolidBrush(backColor)) g.FillRectangle(solidBrush, area); // draw icon g.DrawImage(AllowMirroring, itemImage, area.Left + IMAGE_INSET, area.Top + area.Height / 2 - itemImage.Height / 2); // text format and drawing metrics TextFormatFlags ellipsesStringFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis; int leftMargin = IMAGE_INSET + itemImage.Width + TEXT_INSET; // draw title line // post title int titleWidth = area.Right - leftMargin; Rectangle titleRectangle = new Rectangle(area.Left + leftMargin, area.Top, titleWidth, area.Height); g.DrawText( itemText, e.Font, titleRectangle, textColor, ellipsesStringFormat); // separator line if necessary if (!selected && DroppedDown) { using (Pen pen = new Pen(SystemColors.ControlLight)) g.DrawLine(pen, area.Left, area.Bottom - 1, area.Right, area.Bottom - 1); } // focus rectange if necessary e.DrawFocusRectangle(); }