/// <summary> /// Draws a scroll button for the <see cref="VSNetListBar"/> control. /// </summary> /// <param name="gfx"><see cref="Graphics"/> object to draw onto.</param> /// <param name="rect"><see cref="System.Drawing.Rectangle"/> to draw button in.</param> /// <param name="color">The <see cref="System.Drawing.Color"/> of the background for the button.</param> /// <param name="pressed">Whether the button is pressed or not.</param> /// <param name="enabled">Whether the button is enabled or not.</param> /// <param name="down">If <c>True</c>, the button is a scroll down button, /// otherwise it is a scroll up button.</param> public static void DrawScrollButton( Graphics gfx, Rectangle rect, Color color, bool pressed, bool enabled, bool down ) { if (!enabled) { Brush br = new SolidBrush(CustomBorderColor.ColorLightLight(color)); DrawScrollButtonTriangle(gfx, rect, br, 1, down); br.Dispose(); br = new SolidBrush(CustomBorderColor.ColorDark(color)); DrawScrollButtonTriangle(gfx, rect, br, 0, down); br.Dispose(); } else { DrawScrollButtonTriangle(gfx, rect, SystemBrushes.WindowText, (pressed ? 1 : 0), down); } CustomBorderColor.DrawBorder( gfx, rect, color, true, pressed); }
/// <summary> /// Draws the button for this group bar onto the control. /// </summary> /// <param name="gfx">The graphics object to draw onto.</param> /// <param name="defaultFont">The default font to use to draw the control.</param> /// <param name="controlEnabled">Whether the control is enabled or not.</param> public override void DrawButton( Graphics gfx, Font defaultFont, bool controlEnabled ) { bool rightToLeft = false; Font drawFont = Font; if (Owner != null) { rightToLeft = (Owner.RightToLeft == RightToLeft.Yes); } if (drawFont == null) { drawFont = defaultFont; } // Fill background: Brush br = new SolidBrush(BackColor); gfx.FillRectangle(br, rectangle); br.Dispose(); // Draw the border: CustomBorderColor.DrawBorder( gfx, rectangle, BackColor, false, (MouseDown && MouseOver)); // Draw the text: RectangleF textRect = new RectangleF( rectangle.Left + 2F, rectangle.Top + 1F, rectangle.Width - 4F, rectangle.Height - 2F); StringFormat fmt = new StringFormat(StringFormatFlags.LineLimit | (rightToLeft ? StringFormatFlags.DirectionRightToLeft : 0)); fmt.Alignment = StringAlignment.Near; fmt.LineAlignment = StringAlignment.Center; fmt.Trimming = StringTrimming.EllipsisWord; if (controlEnabled) { br = new SolidBrush(ForeColor); gfx.DrawString(Caption, drawFont, br, textRect, fmt); br.Dispose(); } else { textRect.Offset(1F, 1F); gfx.DrawString(Caption, drawFont, SystemBrushes.ControlLightLight, textRect, fmt); textRect.Offset(-1F, -1F); gfx.DrawString(Caption, drawFont, SystemBrushes.ControlDark, textRect, fmt); } fmt.Dispose(); }
/// <summary> /// Draws this item into the specified graphics object. /// </summary> /// <param name="gfx">The graphics object to draw onto.</param> /// <param name="ils">The ImageList to source icons from.</param> /// <param name="defaultFont">The default font to use to draw the button.</param> /// <param name="style">The style (Outlook version) to draw using.</param> /// <param name="view">The view (large or small icons) to draw using.</param> /// <param name="scrollOffset">The offset of the first item from the /// (0,0) point in the graphics object.</param> /// <param name="skipDrawText">Whether to skip drawing text or not /// (the item is being edited)</param> /// <param name="controlEnabled">Whether the control is enabled or not.</param> public override void DrawButton( Graphics gfx, ImageList ils, Font defaultFont, ListBarDrawStyle style, ListBarGroupView view, int scrollOffset, bool controlEnabled, bool skipDrawText ) { bool rightToLeft = false; Font drawFont = Font; if (drawFont == null) { drawFont = defaultFont; } Color backColor = Color.FromKnownColor(KnownColor.Control); if (Owner != null) { if (Owner.RightToLeft == RightToLeft.Yes) { rightToLeft = true; } backColor = Owner.BackColor; } Rectangle drawRect = new Rectangle(Location, new Size(Width, Height)); drawRect.Offset(0, scrollOffset); if (((Selected) && (!MouseOver)) || (MouseOver && MouseDown)) { // Draw the background: VSNetListBarUtility.DrawSelectedItemBackground(gfx, drawRect); } Rectangle itemRect = drawRect; itemRect.Inflate(-1, -1); if ((Selected) || (MouseDown && MouseOver)) { itemRect.Offset(1, 1); } RectangleF textRect; // Draw the icon: if (rightToLeft) { iconRectangle = new Rectangle( itemRect.Right - ils.ImageSize.Width - 4, itemRect.Top + (itemRect.Height - ils.ImageSize.Height) / 2, ils.ImageSize.Width, ils.ImageSize.Height); textRect = new RectangleF( itemRect.Left, itemRect.Top, itemRect.Width - (ils.ImageSize.Width - 6), itemRect.Height); } else { iconRectangle = new Rectangle( itemRect.Left + 4, itemRect.Top + (itemRect.Height - ils.ImageSize.Height) / 2, ils.ImageSize.Width, ils.ImageSize.Height); textRect = new RectangleF( itemRect.Left + ils.ImageSize.Height + 6, itemRect.Top, itemRect.Width - (ils.ImageSize.Width - 6), itemRect.Height); } if (IconIndex <= ils.Images.Count) { if (Enabled && controlEnabled) { ils.Draw(gfx, iconRectangle.Left, iconRectangle.Top, IconIndex); } else { System.Windows.Forms.ControlPaint.DrawImageDisabled(gfx, ils.Images[IconIndex], iconRectangle.Left, iconRectangle.Top, backColor); } } if ((view == ListBarGroupView.SmallIconsOnly) || (view == ListBarGroupView.LargeIconsOnly)) { textRectangle = new Rectangle(0, 0, 0, 0); skipDrawText = true; } if (!skipDrawText) { // Draw the text: StringFormat format = new StringFormat(StringFormatFlags.LineLimit | (rightToLeft ? StringFormatFlags.DirectionRightToLeft : 0)); format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Center; format.Trimming = StringTrimming.EllipsisWord; if (Enabled && controlEnabled) { Brush br = new SolidBrush(ForeColor); gfx.DrawString(Caption, drawFont, br, textRect, format); br.Dispose(); } else { Brush br = new SolidBrush(CustomBorderColor.ColorLightLight(backColor)); textRect.Offset(1F, 1F); gfx.DrawString(Caption, drawFont, br, textRect, format); br.Dispose(); textRect.Offset(-1F, -1F); br = new SolidBrush(CustomBorderColor.ColorDark(backColor)); gfx.DrawString(Caption, drawFont, br, textRect, format); br.Dispose(); } format.Dispose(); textRectangle = new Rectangle((int)textRect.Left, (int)textRect.Top, (int)textRect.Width, (int)textRect.Height); // TODO_ If mouse over and text too wide show the popup. // Currently a problem with my popup code in that it // foils the Framework's WM_NCACTIVATE processing which // results in spurious focus/mouse over events... } // Draw the border: if (((MouseOver) || (Selected)) && (Enabled)) { CustomBorderColor.DrawBorder(gfx, drawRect, backColor, true, ((MouseDown && MouseOver) || (Selected))); } }