private void DrawTabFace(BidiGraphics g, Color bgColor, Color borderColor, Color lineColor) { Rectangle borderRect = ClientRectangle; if (!Selected) { borderRect.Height -= 2; } // Remove one pixel for the bottom edge of the tab. // We don't want it filled in by the face color as // that would cause the corner pixels of the tab // to be filled in. borderRect.Height -= 1; using (Brush b = new SolidBrush(bgColor)) g.Graphics.FillRectangle(b, borderRect); borderRect.Width -= 1; if (Selected) { borderRect.Y -= 1; } else { borderRect.Height -= 1; } if (clipLeftBorder) { borderRect.X -= 1; borderRect.Width += 1; } if (clipRightBorder) { borderRect.Width += 1; } Region clip = g.Graphics.Clip; clip.Exclude(g.TranslateRectangle(new Rectangle(borderRect.X, borderRect.Bottom, 1, 1))); clip.Exclude(g.TranslateRectangle(new Rectangle(borderRect.Right, borderRect.Bottom, 1, 1))); g.Graphics.Clip = clip; using (Pen p = new Pen(borderColor)) g.DrawRectangle(p, borderRect); if (!Selected) { using (Pen p = new Pen(lineColor)) g.DrawLine(p, 0, 0, ClientSize.Width, 0); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); BidiGraphics g = new BidiGraphics(e.Graphics, ClientSize, false); ColorizedResources colRes = ColorizedResources.Instance; // draw the outer border using (Pen p = new Pen(colRes.BorderDarkColor, 1)) g.DrawRectangle(p, new Rectangle(0, 0, ClientSize.Width - 1, ClientSize.Height - 1)); // draw the caption using (Font f = Res.GetFont(FontSize.Large, FontStyle.Bold)) g.DrawText(Text, f, new Rectangle(19, 8, ClientSize.Width - 1, ClientSize.Height - 1), SystemColors.WindowText, TextFormatFlags.NoPrefix); GdiTextHelper.DrawString(this, labelPublishingTo.Font, _progressMessage, labelPublishingTo.Bounds, false, GdiTextDrawMode.EndEllipsis); }
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 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); }
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> /// Raises the Paint event. /// </summary> /// <param name="e">A PaintEventArgs that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { // Call the base class's method so that registered delegates receive the event. base.OnPaint(e); BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle); // Determine the draw state of the button. DrawState drawState; if (!Enabled) { drawState = DrawState.Disabled; } else if (Latched) { drawState = DrawState.Latched; } else if (Pushed && MouseInside) { drawState = DrawState.Pushed; } else if (MouseInside) { drawState = DrawState.Selected; } else { drawState = DrawState.Enabled; } // Draw the button face, as needed, and select the button bitmap to draw below. Bitmap buttonBitmap = null; switch (drawState) { case DrawState.Disabled: buttonBitmap = BitmapDisabled; break; case DrawState.Enabled: if (Focused) { if (ButtonStyle == ButtonStyle.Standard) { DrawStandardButtonFace(e.Graphics); } else if (ButtonStyle == ButtonStyle.Flat) { DrawFlatButtonFace(e.Graphics); } } buttonBitmap = BitmapEnabled; break; case DrawState.Selected: if (ButtonStyle == ButtonStyle.Standard) { DrawStandardButtonFace(e.Graphics); } else if (ButtonStyle == ButtonStyle.Flat) { DrawFlatButtonFace(e.Graphics); } buttonBitmap = BitmapSelected; break; case DrawState.Latched: case DrawState.Pushed: if (ButtonStyle == ButtonStyle.Standard) { DrawStandardButtonFacePushed(e.Graphics); buttonBitmap = BitmapSelected; } else if (ButtonStyle == ButtonStyle.Flat) { DrawFlatButtonFacePushed(e.Graphics); buttonBitmap = BitmapSelected; } else if (ButtonStyle == ButtonStyle.Bitmap) { buttonBitmap = BitmapPushed; } break; } // Draw the button bitmap, if there is one. if (buttonBitmap != null) { // Set the rectangle into which we'll draw the bitmap. Rectangle drawBitmapRectangle = bitmapRectangle; // if (ButtonStyle != ButtonStyle.Bitmap && drawState == DrawState.Pushed) // drawBitmapRectangle.Offset(ScaleX(PUSHED_OFFSET), ScaleY(PUSHED_OFFSET)); // Draw the bitmap. var destRect = new Rectangle(drawBitmapRectangle.X, drawBitmapRectangle.Y, ScaleX(buttonBitmap.Width), ScaleY(buttonBitmap.Height)); g.DrawImage(AllowMirroring, buttonBitmap, destRect); } // If focus is being shown, and we're focused, draw the focus rectangle. if (ShowFocusCues && Focused) { Rectangle rectangle = ClientRectangle; if (ButtonStyle == ButtonStyle.Flat) { //offset the focus a bit to ensure it draws directly over the flat border rectangle = new Rectangle(rectangle.Location, new Size(ScaleX(rectangle.Width - 1), ScaleY(rectangle.Height - 1))); //clear the background of the rectangle so it contrasts well with the flat selection using (Pen p = new Pen(BackColor)) g.DrawRectangle(p, rectangle); } ControlPaint.DrawFocusRectangle(e.Graphics, rectangle); } // Draw the button text, if there is some. if (ButtonStyle != ButtonStyle.Bitmap && buttonText != null) { // Set the rectangle into which we'll draw the text. Rectangle drawTextRectangle = textRectangle; drawTextRectangle.Offset(HORIZONTAL_TEXT_PAD, VERTICAL_TEXT_PAD); if (drawState == DrawState.Pushed) { drawTextRectangle.Offset(ScaleX(PUSHED_OFFSET), ScaleY(PUSHED_OFFSET)); } TextFormatFlags textFormat; if (ShowKeyboardCues) { textFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding | TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs | TextFormatFlags.EndEllipsis; } else { textFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding | TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs | TextFormatFlags.EndEllipsis | TextFormatFlags.HidePrefix; } // Set the text color. Color textColor = ForeColor; if (!Enabled) { textColor = Color.FromArgb(GraphicsHelper.Opacity(50), textColor); } // Draw the text. g.DrawText(buttonText, Font, drawTextRectangle, textColor, textFormat); } }
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(); }